Python 3 renamed the unicode type to str, the old str type has been replaced by bytes.
if isinstance(unicode_or_str, str):
text = unicode_or_str
decoded = False
else:
text = unicode_or_str.decode(encoding)
decoded = True
You may want to read the Python 3 porting HOWTO for more such details. There is also Lennart Regebro's Porting to Python 3: An in-depth guide, free online.
Last but not least, you could just try to use the 2to3 tool to see how that translates the code for you.
Python 3 renamed the unicode type to str, the old str type has been replaced by bytes.
if isinstance(unicode_or_str, str):
text = unicode_or_str
decoded = False
else:
text = unicode_or_str.decode(encoding)
decoded = True
You may want to read the Python 3 porting HOWTO for more such details. There is also Lennart Regebro's Porting to Python 3: An in-depth guide, free online.
Last but not least, you could just try to use the 2to3 tool to see how that translates the code for you.
If you need to have the script keep working on python2 and 3 as I did, this might help someone
import sys
if sys.version_info[0] >= 3:
unicode = str
and can then just do for example
foo = unicode.lower(foo)
NameError: name 'unicode' is not defined
pyqt4 - name unicode not defined python3 - Stack Overflow
NameError: name 'unicode' is not defined in object_detection/utils/object_detection_evaluation.py
Name 'unicode' is not defined
in python 3 strings are unicode by default.
Remove the unicode function, replace by str.
https://docs.python.org/3.0/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit
There's also a little recipe to make the code python 2 & 3 compatible:
try:
unicode # check if unicode is defined
except NameError: # not found: python 3: replace by str
unicode = str
Like Bakuriu said in his comment, never use a bare except:
Prefer:
except Exception as e:
print("Problem "+repr(e))
# the line below requires some HTML normalization or resulting
# html could be incorrect
import re
ne = re.sub("[^\w]"," ",str(e))
self.browser.append("<font color=red>"+ne+"</font>")
Now you have the real/next exception displayed.
Hope you are using Python 3 , so please replace
Unicode function with String Str function.
def updateUi(self):
try:
text = str(self.lineedit.text()) ##replaced here