Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11471

Re: string to unicode

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'received:verizon.net': 0.07; 'terry': 0.07; 'transform': 0.07; 'python': 0.08; 'csv': 0.09; 'file-like': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:string': 0.09; 'am,': 0.12; 'library': 0.15; 'adam': 0.16; 'codec': 0.16; 'encode': 0.16; 'reedy': 0.16; 'subject:unicode': 0.16; 'mon,': 0.16; 'wrote:': 0.16; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'string': 0.26; 'pass': 0.29; 'unicode': 0.29; 'url:library': 0.31; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'object': 0.35; 'file': 0.36; 'url:python': 0.36; 'using': 0.37; 'open': 0.37; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'williams': 0.66; '11:29': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: string to unicode
Date Mon, 15 Aug 2011 14:29:40 -0400
References <4E493936.5030807@gmail.com> <1313422183.3127.5.camel@linux-yu4c.site>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0
In-Reply-To <1313422183.3127.5.camel@linux-yu4c.site>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.19.1313433008.27778.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313433008 news.xs4all.nl 23841 [2001:888:2000:d::a6]:51426
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11471

Show key headers only | View raw


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


Thread

Re: string to unicode Terry Reedy <tjreedy@udel.edu> - 2011-08-15 14:29 -0400

csiph-web