Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11471
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: string to unicode |
| Date | 2011-08-15 14:29 -0400 |
| References | <4E493936.5030807@gmail.com> <1313422183.3127.5.camel@linux-yu4c.site> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19.1313433008.27778.python-list@python.org> (permalink) |
On 8/15/2011 11:29 AM, Adam Tauno Williams wrote: > On Mon, 2011-08-15 at 08:20 -0700, Artie Ziff wrote: >> if I am using the standard csv library to read contents of a csv file >> which contains Unicode strings (short example: >> '\xe8\x9f\x92\xe8\x9b\x87'), how do I use a python Unicode method such >> as decode or encode to transform this string type into a python unicode >> type? Must I know the encoding (byte groupings) of the Unicode? Can I >> get this from the file? Perhaps I need to open the file with particular >> attributes? > > Open the file with a codec and pass that file-like object to csv. > > codecs.open(filename, mode[, encoding[, errors[, buffering]]]) > > <http://docs.python.org/library/codecs.html#codec-objects> In Python 3, just open with open(... encoding = 'xxx') -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: string to unicode Terry Reedy <tjreedy@udel.edu> - 2011-08-15 14:29 -0400
csiph-web