I'm trying to export a numpy array that contains unicode elements to a text file. So far I got the following to work, but doesn't have any unicode character: import. Software Gratis Foto Kolase. I'm pulling data out of a Google doc, processing it, and writing it to a file (that eventually I will paste into a Wordpress page). It has some non-ASCII symbols.
Pete Shinners wrote: i have a text file of unicode data. I'm not sure how to read this from a file. I can read() it into a massive python string, but cannot get it to convert to unicode. It's definitely inefficient to read it all at once, but i expect the files i'll be reading aren't too large to cause problems.Pete, I think that this is one way to solve the problem. #----------------- import codecs f = codecs.open(filename, 'rt', 'utf-16') data = f.read() f.close # 'data' should now contain unicode data. #----------------- Also, the standard iterator interface seems to be supported by the codecs.open method as well, e.g.
For line in codecs. Escolha Seu Caminho Rar on this page. open(filename, mode, encoding): print line HTH. Alan Kennedy But, of course, it isn't supported all the time:-) If you do this with an utf-16 file, you get the exception 'NotImplementedError:.readline() is not implemented for UTF-16' Which I found surprising. I looked at some other encodings (it would be really nice to have a list of supported encodings;-) to see which others exhibit this behaviour. I wrote this code to check #--------------------------------- import codecs s = 'Hello world n' * 5 encodings = [ 'iso-8859-1', 'ascii', 'utf-16'. Alan Kennedy wrote: Also, the standard iterator interface seems to be supported by the codecs.open method as well, e.g.