Home > front end >  Can I safely remove all u-strings from a project that will only use python 3?
Can I safely remove all u-strings from a project that will only use python 3?

Time:12-27

I work on a project that includes many u"string" in its codebase,

I want to know if I can safely remove the u in front of all those strings knowing that the project will only use Python 3 from now on (it used to use both python 2 and 3)

I have only one source that says :

"The string prefix u is used exclusively for compatibility with Python 2."

CodePudding user response:

Yes. I think you can. Unicode strings are not necessary in Python 3, because all strings are stored as Unicode by default, as stated here.

CodePudding user response:

Yes, you can. The sentence you quoted means that u"string" is in python3 only for compatibility.

In python 3 all strings are unicode so the u is redundant.

CodePudding user response:

I did run test using 2to3 tool and it did change u-string to normal string, ustring.py file before

x = u"string"
print(x)

after 2to3 -w ustring.py

x = "string"
print(x)
  • Related