Re: Obtain Python version number
Andreas Tille writes:
> Hi,
>
> to write a wrapper script I wonder what might be the best possibility
> to find out the version numer of the running python interpreter. The
> wrapper script is of the type
>
> /var/lib/python-support/python${PYVER}/${package}/${realscript}
>
> and I wonder, how I can obtain ${PYVER} according to the version
> of the python binary that is installed as /usr/bin/python.
>
> I tried
>
> PYVER=`python -V 2>&1 | sed 's/Python[[:space:]]\+\([0-9]\+\.[0-9]\+\).*/\1/'`
>
> which works in principle but I wonder if there is some other reasonable
> way.
confused; why a shell script, when trying to get the version of the
*running* interpreter. This should be
import sys
v = sys.version[:3]
It's somewhat communicated that this won't break/change upstream.
Matthias
Reply to: