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


Groups > comp.lang.python > #82297 > unrolled thread

Python 2/3 compatibility code that reads like English!

Started byChris Angelico <rosuav@gmail.com>
First post2014-12-11 03:43 +1100
Last post2014-12-11 03:43 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Python 2/3 compatibility code that reads like English! Chris Angelico <rosuav@gmail.com> - 2014-12-11 03:43 +1100

#82297 — Python 2/3 compatibility code that reads like English!

FromChris Angelico <rosuav@gmail.com>
Date2014-12-11 03:43 +1100
SubjectPython 2/3 compatibility code that reads like English!
Message-ID<mailman.16817.1418229819.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web