Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: [Python-ideas] sys.py3k

Reply
Thread Tools

Re: [Python-ideas] sys.py3k

 
 
Chris Angelico
Guest
Posts: n/a
 
      11-07-2012
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
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-07-2012
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
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      11-08-2012
On Thu, Nov 8, 2012 at 10:56 AM, Steven D'Aprano
<steve+> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57