我怎么知道我正在使用哪个python实现?

时间:2021-01-01 16:09:51

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?

Python有一些不同的实现:CPython,Jython,PyPy等。我想以编程方式确定运行我的代码的实现。我怎样才能做到这一点?

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

具体来说,为我编写一个名为get_implementation_name()的函数:

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

2 个解决方案

#1


52  

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

#2


6  

How about platform

平台怎么样?

it gives you

它给了你

platform.python_implementation()

#1


52  

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

#2


6  

How about platform

平台怎么样?

it gives you

它给了你

platform.python_implementation()