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

Question:

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."

Asked By: Jay D.

||

Answers:

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.

Answered By: kosciej16

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.

Answered By: Florian EDEMESSI

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)
Answered By: Daweo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.