1

我想写入多种语言的文件,然后将其存储在云存储中。这是我的代码:unicode(utf8)写入云存储中的文件,Python

file=gcs.open(filename,'w',content_type='text/html; charset=utf-8') 

     file.write(str(content)) 
     file.close() 

我该如何修改它? 谢谢

+1

如果内容有utf-8,请使用content.encode('utf-8')使它成为二进制。更多信息:http://blog.notdot.net/2010/07/Getting-unicode-right-in-Python – voscausa

+0

非常感谢。现在它正在工作:) – user3376321

回答

3

看起来像这可能是一个在调用file.write之前将字符串编码为UTF-8的问题。如何:

file.write(content.encode('utf-8')) 
+0

是的,这是正确的:)这是我所做的感谢你 – user3376321