[Python-ideas] sys.py3k

Chris Rebert pyideas at rebertia.com
Sun Nov 4 23:02:28 CET 2012

On Sun, Nov 4, 2012 at 1:49 PM, anatoly techtonik <techtonik at gmail.com> wrote:
> if sys.py3k:
>   # some py2k specific code
(I assume your comment has a numeric typo?)
>   pass

You would need that attribute to also be present in Python 2.x for
your snippet to work, and my understanding is that 2.x is closed to
feature additions.

> Why?
>  1. readable
>  2. traceable
> Explained:
>  1. self-explanatory

"py3k" is a nickname/codename that not everyone using Python 3 may know about.

>  2. sys.version_info >= (3, 0) or  sys.version[0] == '3' is harder to
> trace when you need to find all python 3 related hacks

"There should be one-- and preferably only one --obvious way to do
it." Apparently we already have at least 2 ways to do it; let's not
muddle things further by adding yet another.


More information about the Python-ideas mailing list