Determining implementation of Python at runtime? -
i'm writing piece of code returns profiling information , helpful able dynamically return implementation of python in use.
is there pythonic way determine implementation (e.g. jython, pypy) of python code executing on @ runtime? know able version information sys.version
:
>>> import sys >>> sys.version '3.4.3 (default, may 1 2015, 19:14:18) \n[gcc 4.2.1 compatible apple llvm 6.1.0 (clang-602.0.49)]'
but i'm not sure in sys
module implementation code running.
you can use python_implementation
platform
module in python 3 or python 2. returns string identifies python implementation.
e.g.
return_implementation.py
import platform print(platform.python_implementation())
and iterating through responses on command line:
$ in python python3 pypy pypy3; echo -n "implementation $i: "; $i return_implementation.py; done implementation python: cpython implementation python3: cpython implementation pypy: pypy implementation pypy3: pypy
note of answer's date, possible responses 'cpython', 'ironpython', 'jython', 'pypy', meaning it's possible implementation not returned python_implementation
function if not identity sys
module 1 of these types.
python_implementation
calling sys.version
under hood , attempting match response regex pattern -- if there's no conditional match, there's no matching string response.
Comments
Post a Comment