-1

I have a function (below) which uses a unicode function but I receive an "NameError: name 'unicode' is not defined" which leads me to believe I need to import unicode so I tried:

pip install unicode

then:

from unicode import unicode

and I get an error:

ModuleNotFoundError: No module named 'unicode'

The code that calls the unicode function is:

def makelist(table):
  result = []
  allrows = table.findAll('tr')
  for row in allrows:
    result.append([])
    allcols = row.findAll('td')
    for col in allcols:
      thestrings = [unicode(s) for s in col.findAll(text=True)]
      thetext = ''.join(thestrings)
      result[-1].append(thetext)
  return result

What am I doing incorrectly?

Bruce Seymour
  • 1,520
  • 16
  • 24

1 Answers1

2

I suspect that code snippet must be for Python 2, for which unicode() was a built-in function ready to be used without an import. In Python 3, literal strings are Unicode by default, so you don't need to explicitly cast them.

wovano
  • 4,543
  • 5
  • 22
  • 49
PApostol
  • 2,152
  • 2
  • 11
  • 21