fileMain = open("dictionary_15k.txt", "r")
for line1 in fileMain:
dictWords.append(unicode(line1.strip(), "utf-8"))
When compiled it shows
NameError: name 'unicode' is not defined
There is no such name in Python 3, no. You are trying to run Python 2 code in Python 3. In Python 3, unicode
has been renamed to str
.
However, you can remove the unicode()
call altogether; open()
produces a file object that already decodes data to Unicode for you. You probably want to tell it what codec to use, explicitly:
fileMain = open("dictionary_15k.txt", "r", encoding="utf-8")
for line1 in fileMain:
dictWords.append(line1.strip())
You may want to switch to Python 2 if your tutorial is written with that version in mind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With