Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102195
| From | Rob Gaddi <rgaddi@highlandtechnology.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: how to get python version ? |
| Date | 2016-01-28 17:02 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n8dhid$hpv$1@dont-email.me> (permalink) |
| References | <76180516-f465-4fde-a1c4-920c91036623@googlegroups.com> |
namenobodywants@gmail.com wrote:
> hi
>
> is there something analogous to sys.platform that lets you get the version of python you're using? sorry if the question is too see-spot-run. thanks if you can help
>
> peace
> stm
Since everyone else has answered the question you asked, let me answer
the question I think you might have wanted to ask instead.
If what you're trying to determine is simply whether you're running
under Python 2 or 3, then the six package has booleans for six.PY2 and
six.PY3, so you can say things like:
if six.PY2:
def my_fn():
...
else:
def my_fn():
...
Note that checking compatibility this way (calling Python 2 "the weird
one") rather than "if six.PY3" will keep your code compatible in the
future as well.
Bringing in an entire extra package just for one boolean seems
excessive, but if you're actually making that check it's because you've
got a bunch of 2/3 compatibility crap you're having to work out; six
will help will all of that too.
--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
how to get python version ? namenobodywants@gmail.com - 2016-01-27 21:21 -0800 Re: how to get python version ? Ben Finney <ben+python@benfinney.id.au> - 2016-01-28 16:34 +1100 Re: how to get python version ? Rustom Mody <rustompmody@gmail.com> - 2016-01-27 21:48 -0800 Re: how to get python version ? Chris Angelico <rosuav@gmail.com> - 2016-01-28 18:30 +1100 Re: how to get python version ? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-01-28 17:02 +0000
csiph-web