在问这个问题时,我意识到我对原始字符串知之甚少.对于那些自称是Django训练师的人来说,这很糟糕.
我知道编码是什么,而且我知道u''自从我得到什么是Unicode以来我们独自做了什么.
但到底r''做了什么呢?它会产生什么样的字符串?
And above all, what the heck does ur'' do?
Finally, is there any reliable way to go back from a Unicode string to a simple raw string?
Ah, and by the way, if your system and your text editor charset are set to UTF-8, does u'' actually do anything?
有一个很好的方法来做到以下几点?
我写了一个简单的控制台应用程序,使用ftplib从FTP服务器上传和下载文件.
每次下载一些数据块时,我都想更新文本进度条,即使它只是一个数字.
但我不想删除所有打印到控制台的文本.(执行"清除"然后打印更新的百分比.)
我试图解析包含一些非ASCII cheracter的xml,
代码如下所示
from lxml import etree
from lxml import objectify
content = u'<?xml version="1.0" encoding="utf-8"?><div>Order date : 05/08/2013 12:24:28</div>'
mail.replace('\xa0',' ')
xml = etree.fromstring(mail)
Run Code Online (Sandbox Code Playgroud)
但它显示我在'content = ...'这一行上的错误
syntaxError: Non-ASCII character '\xc2' in file /home/projects/ztest/responce.py on line 3,
but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Run Code Online (Sandbox Code Playgroud)
在终端它正在工作,但在eclipse IDE上运行它给了我一个错误.
不知道如何克服..
python ×3
console ×1
encoding ×1
lxml ×1
progress ×1
python-2.x ×1
rawstring ×1
unicode ×1
updating ×1
xml-parsing ×1