Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

When I used the below code:

u = unicode(text, 'utf-8')

I'm getting an error with python 3 saying...

NameError: global name 'unicode' is not defined

Could you please help me to find out how to solve this issue?

1 Answer

0 votes
by (26.4k points)

In python 3, by default they(Literal strings) are unicode.

Let's assume text as a bytes object, then use 

text.decode('utf-8')

Since, unicode in python2 is equal to str in python3, you can write the code as:

str(text, 'utf-8')

If you like it.

Looking for python tutorial? Join python training course to gain more knowledge 

Related questions

0 votes
1 answer
asked Feb 18, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
0 votes
1 answer
asked Sep 27, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...