Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode literals causing invalid syntax

The following code:

s = s.replace(u"&", u"&")

is causing an error in python:

SyntaxError: invalid syntax

removing the u's before the " fixes the problem, but this should work as is? I'm using Python 3.1

like image 901
SupaGu Avatar asked Dec 07 '22 19:12

SupaGu


1 Answers

The u is no longer used in Python 3. String literals are unicode by default. See What's New in Python 3.0.

You can no longer use u"..." literals for Unicode text. However, you must use b"..." literals for binary data.

like image 53
Mark Byers Avatar answered Dec 28 '22 04:12

Mark Byers