Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8179
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| 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; 'wed,': 0.03; 'encoded': 0.05; 'parameter': 0.05; 'does.': 0.07; 'function,': 0.07; 'python': 0.08; "'''": 0.09; 'iterate': 0.09; 'utf-8': 0.09; 'pm,': 0.10; 'def': 0.12; 'received:209.85.214.174': 0.14; 'received:mail-iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'angelico': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Unicode': 0.16; '\xa0for': 0.16; "wouldn't": 0.17; 'bytes': 0.19; 'this?': 0.19; 'work,': 0.20; 'header:In-Reply-To:1': 0.21; 'seems': 0.21; 'file,': 0.22; 'way?': 0.23; '\xa0if': 0.23; "doesn't": 0.25; '(and': 0.25; 'function': 0.25; 'string': 0.26; 'script': 0.27; "i'm": 0.27; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; 'unicode': 0.29; 'bit': 0.30; 'iterating': 0.30; 'hi,': 0.31; 'print': 0.31; 'seem': 0.32; 'to:addr:python-list': 0.33; 'list': 0.33; 'starting': 0.33; 'chris': 0.34; 'using': 0.35; 'received:google.com': 0.37; 'change': 0.37; 'received:209.85': 0.37; 'instead.': 0.37; 'but': 0.38; 'data': 0.38; 'subject:: ': 0.38; "i'd": 0.39; 'received:209': 0.39; 'list,': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'simply': 0.60; 'your': 0.60 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=57Zwa0RZrglgx7r1aHUpFGeReBFqDOhreaOkMRXaoTg=; b=rdRyxkQZt+LtOZh65joLpUScdGcmjfhGBTODaeXkI67By2IATRBDDooSHE0vmcpaF/ waEgKYq+NZ2r5L4YZEN1tQBk4Ov5FFP+NCwxb8KjN7vto9YMJQVhoKsQAeV7gcfhQeER EbJFp7gVlyZgQIPdmawi9jH+i+d84LavCkIhQ= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=mzpdFqQc/lEVva9wd+pOPTQt9Hp84ZhUjrQVN7iiSfXSmW/SxcV7OQgziuBwoVGH3R RbsUp2aR5WWJkJdDOCRtujj2yJ9le1B2bCUZ7k7jkc3gt7Ld86zDIWcX+NV3XEyxQvll OvP97PxsvaVrOw7P1EoYn4+5Ur5EKS89uA2dY= |
| MIME-Version | 1.0 |
| In-Reply-To | <ae8fd9c1-88af-41ef-abb5-3a1883634d0e@glegroupsg2000goo.googlegroups.com> |
| References | <ae8fd9c1-88af-41ef-abb5-3a1883634d0e@glegroupsg2000goo.googlegroups.com> |
| Date | Wed, 22 Jun 2011 14:00:22 +1000 |
| Subject | Re: Unicode codepoints |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| 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.267.1308715226.1164.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1308715226 news.xs4all.nl 49046 [::ffff:82.94.164.166]:57397 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8179 |
Show key headers only | View raw
On Wed, Jun 22, 2011 at 1:37 PM, Saul Spatz <saul.spatz@gmail.com> wrote:
> Hi,
>
> I'm just starting to learn a bit about Unicode. I want to be able to read a utf-8 encoded file, and print out the codepoints it encodes. After many false starts, here's a script that seems to work, but it strikes me as awfully awkward and unpythonic. Have you a better way?
Once you have your data as a Unicode string (and you seem to be using
Python 3, so 's' will be a Unicode string), wouldn't a list of its
codepoints simply be this?
for c in s:
print('U+'+hex(ord(c))[2:])
But if you do need the codePoints() function, I'd do it as a generator.
> def codePoints(s):
> ''' return a list of the Unicode codepoints in the string s '''
> skip = False
> for k, c in enumerate(s):
> if skip:
> skip = False
> yield ord(s[k-1:k+1])
> continue
> if not 0xd800 <= ord(c) <= 0xdfff:
> yield ord(c)
> else:
> skip = True
Your main function doesn't even have to change - it's iterating over
the list, so it may as well iterate over the generator instead.
But I don't really understand what codePoints() does. Is it expecting
the parameter to be a string of bytes or of Unicode characters?
Chris Angelico
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unicode codepoints Saul Spatz <saul.spatz@gmail.com> - 2011-06-21 20:37 -0700
Re: Unicode codepoints Chris Angelico <rosuav@gmail.com> - 2011-06-22 14:00 +1000
Re: Unicode codepoints Vlastimil Brom <vlastimil.brom@gmail.com> - 2011-06-22 10:42 +0200
Re: Unicode codepoints Peter Otten <__peter__@web.de> - 2011-06-22 11:00 +0200
Re: Unicode codepoints jmfauth <wxjmfauth@gmail.com> - 2011-06-22 03:00 -0700
csiph-web