我可以检测到我的代码是在cPython还是Jython上运行? [英] Can I detect if my code is running on cPython or Jython?

查看:159
本文介绍了我可以检测到我的代码是在cPython还是Jython上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型django项目,稍后将部署在一个servlet容器中。但是,如果我使用cPython而不是Jython,开发速度要快得多。所以我想做的是测试我的代码是否在我的settiings.py中的cPython或Jython上运行,所以我可以告诉它使用适当的db驱动程序(postgresql_psycopg2或doj.backends.zxjdbc.postgresql)。有没有一个简单的方法?

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?

推荐答案

如果你正在运行Jython

if you're running Jython

import platform
platform.system()  

返回'Java'

这里有一些讨论,希望这有帮助。

return 'Java'
here has some discussion, hope this helps.

这篇关于我可以检测到我的代码是在cPython还是Jython上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆