Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82297
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'subject:code': 0.07; 'string': 0.09; 'subject:skip:c 10': 0.09; 'type,': 0.09; 'python': 0.11; 'sections': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'through,': 0.16; 'code.': 0.18; 'meant': 0.20; 'to:name:python- list@python.org': 0.22; 'byte': 0.24; 'subject:like': 0.24; 'text,': 0.24; 'unicode': 0.24; 'subject:/': 0.26; 'certain': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'subject:that': 0.31; 'says': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'most': 0.60; "you're": 0.61; 'love': 0.65; 'subject:English': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=GGulVY6bvWsclXjiYVcIEtDkY7GldQ2vJDy8VIkGGjs=; b=LN5ZhqVjtKhLRiBQmzggR0RF/WUhH44bxyAU9aZXVr16dtFShgbLhmpQeQksvlVJbu PDtBj+b4frS1LJ580CAtfD1dxplZ//jSVtkDqHqQrUxcBgo+pTvFHEwQqbZV5GR9NkPc /xUsePTDp6bF2pqJHVmJNivWy3DpltrdoSYnNtmCL672yEHMeJqd4QD3ELLOiod7QCiC zJDvuwQG/0EKC0H7Z+zuhGJ+xeSm458eWfKfKDVh5sEnvVYBtsvEpfjS1wK6Vy15G5NA msggux1/B1pg33jdg7q220QrS45NduPpiPnrCc4CNtNpyjensGSO5d4IDDMeBi7IMcuV 1G4g== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.136.92 with SMTP id k89mr4985885iod.43.1418229816190; Wed, 10 Dec 2014 08:43:36 -0800 (PST) |
| Date | Thu, 11 Dec 2014 03:43:36 +1100 |
| Subject | Python 2/3 compatibility code that reads like English! |
| From | Chris Angelico <rosuav@gmail.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16817.1418229819.18130.python-list@python.org> (permalink) |
| Lines | 13 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418229819 news.xs4all.nl 2917 [2001:888:2000:d::a6]:43035 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:82297 |
Show key headers only | View raw
So you have a string of text, either a Unicode string in Python 3, or
a byte string that's meant to be UTF-8. Most of the way through,
you're working with the native string type, for compatibility with
other sections of code. But then you want to be certain you're working
with a Unicode string...
if str is bytes:
some_string = some_string.decode('UTF-8')
I just love how that condition reads. Who says cross-branch
compatibility code has to be ugly? :)
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Python 2/3 compatibility code that reads like English! Chris Angelico <rosuav@gmail.com> - 2014-12-11 03:43 +1100
csiph-web