How can I tell which python implementation I'm using?

一个人想着一个人 提交于 2020-05-24 09:37:11

问题


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..."

回答1:


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



回答2:


How about platform

it gives you

platform.python_implementation()


来源:https://stackoverflow.com/questions/14718135/how-can-i-tell-which-python-implementation-im-using

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!