I am passing with a code base that is using the smart_str
method of Django:
for p in pro:
print smart_str(p["title"])
I want to replace it with a native python solution without involving django inside but I am not sure what smart_str
exactly do:
smart_str(s, encoding='utf-8', strings_only=False, errors='strict')
Alias of smart_bytes() on Python 2 and smart_text() on Python 3. This function returns a str or a lazy string.
and
smart_bytes(s, encoding='utf-8', strings_only=False,errors='strict')
Returns a bytestring version of s, encoded as specified in encoding.
If strings_only is True, don’t convert (some) non-string-like objects.
Could we replace it simply with print unicode(u'xa1').encode("utf-8")
?
Aucun commentaire:
Enregistrer un commentaire