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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -