有什么策略可以编写可在CPython,Jython和IronPython中使用的python代码 [英] What are some strategies to write python code that works in CPython, Jython and IronPython
本文介绍了有什么策略可以编写可在CPython,Jython和IronPython中使用的python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图同时针对两个环境,我可以放心地说,如果必须使用数据库等,最终必须为该环境编写唯一的代码.您有一个很好的方法来处理这种情况吗?
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?
推荐答案
如果要做,则需要为环境编写唯一的代码,请使用pythons
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
在一个简单的模块("module_importer"?)中拥有这些东西,并像这样编写您的代码:
have this stuff in a simple module (''module_importer''?) and write your code like this:
from module_importer import mymodule
这样,您要做的就是在每个平台上更改module_importer.py
.
This way, all you need to do is alter module_importer.py
per platform.
这篇关于有什么策略可以编写可在CPython,Jython和IronPython中使用的python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文