Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some strategies to write python code that works in CPython, Jython and IronPython

Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation?

like image 998
minty Avatar asked Sep 10 '08 07:09

minty


People also ask

What are the difference in CPython Jython and IronPython?

Just as Jython is an implementation of Python on the JVM, IronPython is an implementation of Python on the . Net runtime, or CLR (Common Language Runtime). IronPython uses the DLR (Dynamic Language Runtime) of the CLR to allow Python programs to run with the same degree of dynamism that they do in CPython.

What makes the CPython different from Python?

CPython is the original Python implementation. It is the implementation you download from Python.org. People call it CPython to distinguish it from other, later, Python implementations, and to distinguish the implementation of the language engine from the Python programming languageitself.

What is the difference between CPython and PyPy?

PyPy is a drop-in replacement for the stock Python interpreter, CPython. Whereas CPython compiles Python to intermediate bytecode that is then interpreted by a virtual machine, PyPy uses just-in-time (JIT) compilation to translate Python code into machine-native assembly language.


1 Answers

If you do find you need to write unique code for an environment, use pythons

import mymodule_jython as mymodule

import mymodule_cpython as mymodule

have this stuff in a simple module (''module_importer''?) and write your code like this:

from module_importer import mymodule

This way, all you need to do is alter module_importer.py per platform.

like image 73
Daren Thomas Avatar answered Sep 28 '22 07:09

Daren Thomas