0

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?

0

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.