You are not logged in.
So, I'm building a very basic script to utilize the simple webserver in python. For the sake of portability, I would like it to recognise whether it's running on python 2.x or python 3.x.
Here's the problem:
user ~$ python --version | egrep -o '[0-9]\.[0-9]*\.[0-9]'
Python 3.2.2
Well, that's akward. Let's try with e.g. man to see if egrep works with other programs:
user ~$ man --version | egrep -o '[0-9]\.[0-9]*\.[0-9]'
2.6.0
How come python isn't behaving like all other programs when it comes to this?
Last edited by graph (2012-01-20 14:39:41)
Offline
Use the following to directly print the major version of Python:
python -c 'import sys; print(sys.version_info[0])'
Or just run the Python script directly with Python 2 or Python 3 (depending on what version it needs) with "python2" and "python3" respectively.
Last edited by lunar (2012-01-20 14:24:44)
Offline
Because `python --version` prints to stderr, so you have to use:
python --version 2>&1 | egrep -o '[0-9]\.[0-9]*\.[0-9]'
You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.
Offline
Because `python --version` prints to stderr, so you have to use:
python --version 2>&1 | egrep -o '[0-9]\.[0-9]*\.[0-9]'
Haha I was so close! Except that I wrote it &2>1, which of course didn't work.
Thank you so much, I was about to go crazy for a minute here.
I even made a temporally fix, just to prove to my computer that I was still in charge:
ls -d /usr/lib/python* | egrep -o '[0-9].[0-9]*' | cut -d. -f1 | sort -n | tail -1
Last edited by graph (2012-01-20 14:41:37)
Offline
If you're OK with parsing the output of ls, why not
ls -d /usr/lib/python* | cut -c 16 | tail -1
Offline