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


Groups > comp.lang.python > #32756

Re: [Python-ideas] sys.py3k

References <CAPkN8xL1Hh72_cur91xTPVcyxMLzMVPpZcUp_oumUFKhMZZTDg@mail.gmail.com> <5096ED46.20502@pearwood.info>
Date 2012-11-05 18:36 +1100
Subject Re: [Python-ideas] sys.py3k
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3273.1352101022.27098.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web