Google App Engine:CSV 的编码类型?
我正在尝试使用 appcfg.py upload_data
上传数据。我的 CSV 编码为 ANSI,但 Alex Martelli 说它可能应该是 UTF-8。所以我改用了(使用 Notepad++)。
这在我的文件的第一个字符处遇到了错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
所以然后我切换回 ANSI,我得到这个:
Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
嗯...看起来其他人也有类似的问题 此处。如何使用 Notepad++ 最有效地删除每行末尾的换行符?或者还有什么我应该做的事情?
I am trying to upload data using appcfg.py upload_data
. My CSV was encoded as ANSI, but Alex Martelli said that it should probably be UTF-8. So I switched to that (using Notepad++).
This hit an error at the very first character of my file:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
So then I switch back to ANSI, I get this:
Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
Hmmm... Looks like someone else had a similar problem here. How would I remove the newlines at the end of the each line most efficiently using Notepad++? Or is there something else I'm supposed to be doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过 HTTP(可能是 UTF-8)获取文件时,我遇到了类似的问题。我通过首先使用以下方法将字符串转换为 unicode 来修复它:
然后每次我需要以 ascii 形式访问它时,我都会编码回 UTF-8:
当尝试使用 ElementTree (fromstring) 解析 XML 文件时,这对我有用
I had a similar issue when fetching files over HTTP, which could be UTF-8. I fixed it by first converting the string to unicode using:
Then every time I need to access it as ascii I would encode back as UTF-8:
This worked for me when trying to parse an XML file with ElementTree (fromstring)