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


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

Re: [Python-ideas] sys.py3k

Started byChris Angelico <rosuav@gmail.com>
First post2012-11-05 18:36 +1100
Last post2012-11-05 18:36 +1100
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [Python-ideas] sys.py3k Chris Angelico <rosuav@gmail.com> - 2012-11-05 18:36 +1100

#32756 — Re: [Python-ideas] sys.py3k

FromChris Angelico <rosuav@gmail.com>
Date2012-11-05 18:36 +1100
SubjectRe: [Python-ideas] sys.py3k
Message-ID<mailman.3273.1352101022.27098.python-list@python.org>
On Mon, Nov 5, 2012 at 9:33 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> On 05/11/12 08:49, anatoly techtonik wrote:
>>
>> if sys.py3k:
>>    # some py2k specific code
>>    pass
>
> # Bring back reload in Python 3.
> try:
>     reload
> except NameError:
>     from imp import reload
>
> try:
>     any
> except NameError:
>     # Python 2.4 compatibility.
>     def any(items):
>         for item in items:
>             if item:
>                 return True
>         return False

Take the best of both worlds:

try: # py3k
    reload
except NameError:
    from imp import reload

Now you can grep your code for py3k without changing the language!

Never underestimate the value of comment tokens. Universal ones like
TODO or private ones like NULLSAFE, all it takes is grep or your
editor's Find function to make them all obvious.

ChrisA

[toc] | [standalone]


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


csiph-web