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


Groups > comp.lang.python > #32913

Re: [Python-ideas] sys.py3k

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'subject:Python': 0.05; 'try:': 0.07; 'python': 0.09; 'files"': 0.09; 'grep': 0.09; 'nameerror:': 0.09; '"grep': 0.16; 'anatoly': 0.16; 'better:': 0.16; 'conversion)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hacks': 0.16; 'reload': 0.16; 'subject:ideas': 0.16; 'switch.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'bytes': 0.17; 'else,': 0.17; 'thu,': 0.17; 'code,': 0.18; 'subject:] ': 0.19; 'import': 0.21; 'received:209.85.214.174': 0.21; 'constant': 0.22; 'explicit': 0.22; 'help.': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; '(such': 0.27; 'message-id:@mail.gmail.com': 0.27; 'all.': 0.28; 'source': 0.29; 'keyword': 0.30; 'code': 0.31; 'file': 0.32; 'anywhere': 0.33; 'maintained': 0.33; 'to:addr:python-list': 0.33; 'agree': 0.34; 'received:google.com': 0.34; 'consistent': 0.35; 'nov': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'should': 0.36; 'enough': 0.36; 'received:209': 0.37; 'comment': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'easily': 0.39; 'subject:-': 0.40; 'header:Received:5': 0.40; 'most': 0.61; 'remove': 0.61; 'more': 0.63; 'taking': 0.65; 'useful.': 0.65; 'carefully': 0.71; 'unusual': 0.71
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=02cqnbSqH5FvTab0b5xqJTy14X9aU2+vtRLLcW0HT2I=; b=jzt1S0IsjC5AfmVZzP7gYdMW7gc7k/ROxOgycg1JNiGsHC1CqK0L83mNUn5+gln2n2 NSlJMrOw4/dvCMeMgjLd/Z7ZTjjrkVpZR2EhmexbToKmTfDx8y6iz/cdITjJ6dVe8pGC oOqZmQ6k3x+yp3QHA+Z+uJKg9Qhb0M8E82XPTejZ6Y+lGHPanXSd9rjbqn+RzyKaZjK6 ljbys1izcBoxEeHiXPb7i4qqEx8y/tnyFWvh+JkdfzPjxgzlmEtsWi7O8W2j2ZfwsU5c P/nOWlus1hMriL+jm2ZEAWObajOaS4JN3GJpNBYJ9ks0O61iS+evUF/5LFz9Phwk57zt Nywg==
MIME-Version 1.0
In-Reply-To <CAPkN8xLbr1Xn+m_LWw92KKrVB5K7AeZs_+Ju9CZq0Q=yG-5wSA@mail.gmail.com>
References <CAPkN8xL1Hh72_cur91xTPVcyxMLzMVPpZcUp_oumUFKhMZZTDg@mail.gmail.com> <5096ED46.20502@pearwood.info> <CAHVvXxSJ1wP8+VK1gZP5cyCL9Xr9iu209DeQWgGAOo4AmZ6UZQ@mail.gmail.com> <20121105063008.GA14836@ando> <CAPkN8xLbr1Xn+m_LWw92KKrVB5K7AeZs_+Ju9CZq0Q=yG-5wSA@mail.gmail.com>
Date Thu, 8 Nov 2012 10:14:35 +1100
Subject Re: [Python-ideas] sys.py3k
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3401.1352330078.27098.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352330078 news.xs4all.nl 6949 [2001:888:2000:d::a6]:34859
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32913

Show key headers only | View raw


On Thu, Nov 8, 2012 at 5:35 AM, anatoly techtonik <techtonik@gmail.com> 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

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


Thread

Re: [Python-ideas] sys.py3k Chris Angelico <rosuav@gmail.com> - 2012-11-08 10:14 +1100
  Re: [Python-ideas] sys.py3k Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-07 23:56 +0000
    Re: [Python-ideas] sys.py3k Chris Angelico <rosuav@gmail.com> - 2012-11-08 11:06 +1100

csiph-web