如何判断我正在使用哪个python实现? [英] How can I tell which python implementation I'm using?

查看:84
本文介绍了如何判断我正在使用哪个python实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python有一些不同的实现:CPython,Jython,PyPy等。我想以编程方式确定我的代码在哪个实现上运行。我该怎么办呢? p>

  impl_name = get_implementation_name()
if impl_name == CPython:
print我可以滥用CPython实现详细信息。(我是一个坏人,坏人。)
elif impl_name == PyPy:
打印在这里不能指望引用计数垃圾回收...
其他:
打印我最好小心点...


解决方案

 在[50]:导入平台
在[52]:platform.python_implementation()
出[52]:'CPython'


Python has a few different implementations: CPython, Jython, PyPy, etc. I want to programmatically determine which implementation my code is running on. How can I do that?

To be specific, write a function called get_implementation_name() for me:

impl_name = get_implementation_name()
if impl_name == "CPython":
  print "I can abuse CPython implementation details. (I'm a bad, bad man.)"
elif impl_name == "PyPy":
  print "Can't count on reference-counting garbage collection here..."
else:
  print "I better be careful..."

解决方案

In [50]: import platform    
In [52]: platform.python_implementation()
Out[52]: 'CPython'

这篇关于如何判断我正在使用哪个python实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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