11
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
Jason
  • 2,278
  • 2
  • 17
  • 25
Soty
  • 129
  • 1
  • 1
  • 4

1 Answers1

28

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343