Re: [Python-ideas] sys.py3k

Discussion in 'Python' started by Chris Angelico, Nov 5, 2012.

  1. On Mon, Nov 5, 2012 at 9:33 AM, Steven D'Aprano <> 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
    Chris Angelico, Nov 5, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald Meier
    Replies:
    2
    Views:
    1,467
    Keith S.
    Oct 21, 2003
  2. Roman Neuhauser
    Replies:
    0
    Views:
    645
    Roman Neuhauser
    Apr 4, 2005
  3. Replies:
    2
    Views:
    640
    velle
    Jan 5, 2006
  4. Jean-Paul Calderone
    Replies:
    0
    Views:
    451
    Jean-Paul Calderone
    Oct 30, 2007
  5. Chris Angelico

    Re: [Python-ideas] sys.py3k

    Chris Angelico, Nov 7, 2012, in forum: Python
    Replies:
    2
    Views:
    136
    Chris Angelico
    Nov 8, 2012
Loading...

Share This Page