Re: [Python-ideas] sys.py3k

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

  1. On Thu, Nov 8, 2012 at 5:35 AM, anatoly techtonik <> wrote:
    > I thought of sys.py3k check as an explicit way to guard the code that should
    > be maintained extra carefully for Python 3 compatibility, so that you can
    > grep the source for this constant and remove all the hacks (such as bytes to
    > string conversion) required to maintain the compatibility when the time
    > comes to switch.


    I agree about greppability, it's a huge help. Hence the code comment;
    as long as you're consistent and you pick a keyword long enough or
    unusual enough to not occur anywhere else, you can easily do a "find
    across files" or "grep XYZ *" to find them all. And if you put the
    comment on the most significant line of code, line-based tools will be
    more useful.

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

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

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

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

    Taking just the line with the keyword "py3k" on it will tell you
    exactly what that file is doing.

    ChrisA
     
    Chris Angelico, Nov 7, 2012
    #1
    1. Advertising

  2. On Thu, 08 Nov 2012 10:14:35 +1100, Chris Angelico wrote:

    > On Thu, Nov 8, 2012 at 5:35 AM, anatoly techtonik <>
    > wrote:
    >> I thought of sys.py3k check ...


    Chris, you regularly reply to the wrong mailing list, and you've just
    done it again. This is not python-ideas.



    --
    Steven
     
    Steven D'Aprano, Nov 7, 2012
    #2
    1. Advertising

  3. On Thu, Nov 8, 2012 at 10:56 AM, Steven D'Aprano
    <> wrote:
    > On Thu, 08 Nov 2012 10:14:35 +1100, Chris Angelico wrote:
    >
    >> On Thu, Nov 8, 2012 at 5:35 AM, anatoly techtonik <>
    >> wrote:
    >>> I thought of sys.py3k check ...

    >
    > Chris, you regularly reply to the wrong mailing list, and you've just
    > done it again. This is not python-ideas.


    Ack! Sorry all. I was sure I checked.... whoops.

    Egg-on-face-ly yours...

    ChrisA
     
    Chris Angelico, Nov 8, 2012
    #3
    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,542
    Keith S.
    Oct 21, 2003
  2. Roman Neuhauser
    Replies:
    0
    Views:
    677
    Roman Neuhauser
    Apr 4, 2005
  3. Replies:
    2
    Views:
    679
    velle
    Jan 5, 2006
  4. Jean-Paul Calderone
    Replies:
    0
    Views:
    469
    Jean-Paul Calderone
    Oct 30, 2007
  5. Chris Angelico

    Re: [Python-ideas] sys.py3k

    Chris Angelico, Nov 5, 2012, in forum: Python
    Replies:
    0
    Views:
    261
    Chris Angelico
    Nov 5, 2012
Loading...

Share This Page