Unicode文字导致语法无效 [英] Unicode literals causing invalid syntax

查看:140
本文介绍了Unicode文字导致语法无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码:

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

导致python中的错误:

is causing an error in python:

SyntaxError: invalid syntax

在解决"之前删除u的问题,但这应该可以正常工作吗?我正在使用Python 3.1

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

推荐答案

Python 3中不再使用u.字符串字面量默认情况下是unicode.参见

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

您不能再将u"..."文字用于Unicode文本.但是,对于二进制数据,必须使用b"..."文字.

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

这篇关于Unicode文字导致语法无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆