I have following code in Pyhton:
# myFile.csv tend to looks like:
# 'a1', 'ふじさん', 'c1'
# 'a2', 'ふじさん', 'c2'
# 'a3', 'ふじさん', 'c3'
s = u"unicodeText" # unicodeText like, ふじさん بعدة أش 일본富士山Ölkələr
with codecs.open('myFile.csv', 'w+', 'utf-8') as f: # codecs open
f.write(s.encode('utf-8', 'ignore'))
- I was using Vim to edit the code and using Vim to open "myFile.csv";
- It can success display unicode text from terminal;
- but not able to display unicode text from Excel, nor from browser;
- My platform is osx
I don't know if is my configuration problem or actually I code it wrong way, if you any idea, please advise. Deeply appreciate!
change open to codecs.open.
Thanks for point out f.close(), deleted.
xlsorcsvfiles in the way you are trying to do it. You need to use a specialized module, such as xlrd forxlsfiles, or the csv module forcsvfiles.xls, but writing acsvfile does not require a special module.csvmodule exists for a good reason, and since it's part of the stdlib, it makes no sense not to use it.f.close()when the file is opened as the context manager for thewithstatement.