I'm working on a small django project that will be deployed in a servlet container later. But development is much faster if I work with cPython instead of Jython. So what I want to do is test if my code is running on cPython or Jython in my settiings.py so I can tell it to use the appropriate db driver (postgresql_psycopg2 or doj.backends.zxjdbc.postgresql). Is there a simple way to do this?
Reference implementation of Python, called CPython, is written in C language. Jython on the other hand is completely written in Java and is a JVM implementation. Standard Python is available on multiple platforms. Jython is available for any platform with a JVM installed on it.
Written in C and Python, CPython is the default and most widely used implementation of the Python language. CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it.
Check Python Version: Script To check which Python version is running, you can use either the sys or the platform module. The script will be the same for Windows, macOS, and Linux. Of course, you can easily obtain the individual components of this tuple using an index (e.g. sys. version_info[0] ) or a name (e.g. sys.
Python is an interpreted language, which means the source code of a Python program is converted into bytecode that is then executed by the Python virtual machine. Python is different from major compiled languages, such as C and C + +, as Python code is not required to be built and linked like code for these languages.
In Python 3.3 and beyond you can use sys.implementation and look at the name
attribute.
The most clear-cut way is:
import platform
platform.python_implementation()
'CPython'
By default, most of the time the underlying interpreter is CPython only which is also arguably the most efficient one :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With