How can I tell which python implementation I'm using?
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..."
python cpython
add a comment |
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..."
python cpython
3
"write a function for me" is never a good thing to say in a question.
– millimoose
Feb 5 '13 at 22:24
5
I disagree. Strongly. We're programmers. Sometimes code is clearer than prose. Saying "Here's some code, please fill in the missing function" can be a very concise way of explaining what your requirements are, and it eliminates some potential sources of confusion.
– Stuart Berg
Feb 5 '13 at 22:31
5
It comes across as demanding and makes you seem like a "plz send me the codes" person. Which might not be the case for your question, but you're risking triggering the lizard brain in readers making them skip your question before re-reading it properly. Understand that the point of question criticism here isn't to make you feel dumb for doing something wrong, but to tell you how to attract and retain the most attention for your question. (See also: the pointless defensive PS.)
– millimoose
Feb 5 '13 at 22:39
3
Sure. Sorry if my comment sounded defensive. Thanks for the advice.
– Stuart Berg
Feb 5 '13 at 22:42
3
Yah, I'm in full agreement with superbatfish here. This remains the most concisely, unambiguously, and humorously phrased variant of a question guaranteed to invite confusion and ambiguity. I mean:"I can abuse CPython implementation details."
C'mon! That's awesome. superbatfish should be praised – not chastised – for the Pythonesque tongue-in-cheek.
– Cecil Curry
Sep 3 '16 at 5:53
add a comment |
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..."
python 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..."
python cpython
python cpython
edited Feb 5 '13 at 22:43
asked Feb 5 '13 at 22:22
Stuart Berg
7,92874067
7,92874067
3
"write a function for me" is never a good thing to say in a question.
– millimoose
Feb 5 '13 at 22:24
5
I disagree. Strongly. We're programmers. Sometimes code is clearer than prose. Saying "Here's some code, please fill in the missing function" can be a very concise way of explaining what your requirements are, and it eliminates some potential sources of confusion.
– Stuart Berg
Feb 5 '13 at 22:31
5
It comes across as demanding and makes you seem like a "plz send me the codes" person. Which might not be the case for your question, but you're risking triggering the lizard brain in readers making them skip your question before re-reading it properly. Understand that the point of question criticism here isn't to make you feel dumb for doing something wrong, but to tell you how to attract and retain the most attention for your question. (See also: the pointless defensive PS.)
– millimoose
Feb 5 '13 at 22:39
3
Sure. Sorry if my comment sounded defensive. Thanks for the advice.
– Stuart Berg
Feb 5 '13 at 22:42
3
Yah, I'm in full agreement with superbatfish here. This remains the most concisely, unambiguously, and humorously phrased variant of a question guaranteed to invite confusion and ambiguity. I mean:"I can abuse CPython implementation details."
C'mon! That's awesome. superbatfish should be praised – not chastised – for the Pythonesque tongue-in-cheek.
– Cecil Curry
Sep 3 '16 at 5:53
add a comment |
3
"write a function for me" is never a good thing to say in a question.
– millimoose
Feb 5 '13 at 22:24
5
I disagree. Strongly. We're programmers. Sometimes code is clearer than prose. Saying "Here's some code, please fill in the missing function" can be a very concise way of explaining what your requirements are, and it eliminates some potential sources of confusion.
– Stuart Berg
Feb 5 '13 at 22:31
5
It comes across as demanding and makes you seem like a "plz send me the codes" person. Which might not be the case for your question, but you're risking triggering the lizard brain in readers making them skip your question before re-reading it properly. Understand that the point of question criticism here isn't to make you feel dumb for doing something wrong, but to tell you how to attract and retain the most attention for your question. (See also: the pointless defensive PS.)
– millimoose
Feb 5 '13 at 22:39
3
Sure. Sorry if my comment sounded defensive. Thanks for the advice.
– Stuart Berg
Feb 5 '13 at 22:42
3
Yah, I'm in full agreement with superbatfish here. This remains the most concisely, unambiguously, and humorously phrased variant of a question guaranteed to invite confusion and ambiguity. I mean:"I can abuse CPython implementation details."
C'mon! That's awesome. superbatfish should be praised – not chastised – for the Pythonesque tongue-in-cheek.
– Cecil Curry
Sep 3 '16 at 5:53
3
3
"write a function for me" is never a good thing to say in a question.
– millimoose
Feb 5 '13 at 22:24
"write a function for me" is never a good thing to say in a question.
– millimoose
Feb 5 '13 at 22:24
5
5
I disagree. Strongly. We're programmers. Sometimes code is clearer than prose. Saying "Here's some code, please fill in the missing function" can be a very concise way of explaining what your requirements are, and it eliminates some potential sources of confusion.
– Stuart Berg
Feb 5 '13 at 22:31
I disagree. Strongly. We're programmers. Sometimes code is clearer than prose. Saying "Here's some code, please fill in the missing function" can be a very concise way of explaining what your requirements are, and it eliminates some potential sources of confusion.
– Stuart Berg
Feb 5 '13 at 22:31
5
5
It comes across as demanding and makes you seem like a "plz send me the codes" person. Which might not be the case for your question, but you're risking triggering the lizard brain in readers making them skip your question before re-reading it properly. Understand that the point of question criticism here isn't to make you feel dumb for doing something wrong, but to tell you how to attract and retain the most attention for your question. (See also: the pointless defensive PS.)
– millimoose
Feb 5 '13 at 22:39
It comes across as demanding and makes you seem like a "plz send me the codes" person. Which might not be the case for your question, but you're risking triggering the lizard brain in readers making them skip your question before re-reading it properly. Understand that the point of question criticism here isn't to make you feel dumb for doing something wrong, but to tell you how to attract and retain the most attention for your question. (See also: the pointless defensive PS.)
– millimoose
Feb 5 '13 at 22:39
3
3
Sure. Sorry if my comment sounded defensive. Thanks for the advice.
– Stuart Berg
Feb 5 '13 at 22:42
Sure. Sorry if my comment sounded defensive. Thanks for the advice.
– Stuart Berg
Feb 5 '13 at 22:42
3
3
Yah, I'm in full agreement with superbatfish here. This remains the most concisely, unambiguously, and humorously phrased variant of a question guaranteed to invite confusion and ambiguity. I mean:
"I can abuse CPython implementation details."
C'mon! That's awesome. superbatfish should be praised – not chastised – for the Pythonesque tongue-in-cheek.– Cecil Curry
Sep 3 '16 at 5:53
Yah, I'm in full agreement with superbatfish here. This remains the most concisely, unambiguously, and humorously phrased variant of a question guaranteed to invite confusion and ambiguity. I mean:
"I can abuse CPython implementation details."
C'mon! That's awesome. superbatfish should be praised – not chastised – for the Pythonesque tongue-in-cheek.– Cecil Curry
Sep 3 '16 at 5:53
add a comment |
2 Answers
2
active
oldest
votes
In [50]: import platform
In [52]: platform.python_implementation()
Out[52]: 'CPython'
3
Well, I feel dumb. I suppose an acceptable answer would have been:import platform; get_implementation_name = platform.python_implementation
:-)
– Stuart Berg
Feb 5 '13 at 22:33
1
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
1
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
add a comment |
How about platform
it gives you
platform.python_implementation()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14718135%2fhow-can-i-tell-which-python-implementation-im-using%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In [50]: import platform
In [52]: platform.python_implementation()
Out[52]: 'CPython'
3
Well, I feel dumb. I suppose an acceptable answer would have been:import platform; get_implementation_name = platform.python_implementation
:-)
– Stuart Berg
Feb 5 '13 at 22:33
1
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
1
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
add a comment |
In [50]: import platform
In [52]: platform.python_implementation()
Out[52]: 'CPython'
3
Well, I feel dumb. I suppose an acceptable answer would have been:import platform; get_implementation_name = platform.python_implementation
:-)
– Stuart Berg
Feb 5 '13 at 22:33
1
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
1
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
add a comment |
In [50]: import platform
In [52]: platform.python_implementation()
Out[52]: 'CPython'
In [50]: import platform
In [52]: platform.python_implementation()
Out[52]: 'CPython'
answered Feb 5 '13 at 22:25
unutbu
540k10011551223
540k10011551223
3
Well, I feel dumb. I suppose an acceptable answer would have been:import platform; get_implementation_name = platform.python_implementation
:-)
– Stuart Berg
Feb 5 '13 at 22:33
1
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
1
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
add a comment |
3
Well, I feel dumb. I suppose an acceptable answer would have been:import platform; get_implementation_name = platform.python_implementation
:-)
– Stuart Berg
Feb 5 '13 at 22:33
1
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
1
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
3
3
Well, I feel dumb. I suppose an acceptable answer would have been:
import platform; get_implementation_name = platform.python_implementation
:-)– Stuart Berg
Feb 5 '13 at 22:33
Well, I feel dumb. I suppose an acceptable answer would have been:
import platform; get_implementation_name = platform.python_implementation
:-)– Stuart Berg
Feb 5 '13 at 22:33
1
1
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
@DSM: Yes, platform.python_implementation was introduced in Python2.6.
– unutbu
Feb 5 '13 at 22:36
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
Well, that goes to show you what happens when I don't stay current!
– DSM
Feb 5 '13 at 22:37
1
1
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
Can we change the python implementation from Cpython to pypy? If yes, How can we do this?
– gaurav parashar
Mar 16 '16 at 9:40
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
@gauravparashar if you have a separate question, ask it separately
– OrangeDog
Nov 28 '17 at 14:27
add a comment |
How about platform
it gives you
platform.python_implementation()
add a comment |
How about platform
it gives you
platform.python_implementation()
add a comment |
How about platform
it gives you
platform.python_implementation()
How about platform
it gives you
platform.python_implementation()
answered Feb 5 '13 at 22:26
Jakob Bowyer
22.7k65381
22.7k65381
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14718135%2fhow-can-i-tell-which-python-implementation-im-using%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
"write a function for me" is never a good thing to say in a question.
– millimoose
Feb 5 '13 at 22:24
5
I disagree. Strongly. We're programmers. Sometimes code is clearer than prose. Saying "Here's some code, please fill in the missing function" can be a very concise way of explaining what your requirements are, and it eliminates some potential sources of confusion.
– Stuart Berg
Feb 5 '13 at 22:31
5
It comes across as demanding and makes you seem like a "plz send me the codes" person. Which might not be the case for your question, but you're risking triggering the lizard brain in readers making them skip your question before re-reading it properly. Understand that the point of question criticism here isn't to make you feel dumb for doing something wrong, but to tell you how to attract and retain the most attention for your question. (See also: the pointless defensive PS.)
– millimoose
Feb 5 '13 at 22:39
3
Sure. Sorry if my comment sounded defensive. Thanks for the advice.
– Stuart Berg
Feb 5 '13 at 22:42
3
Yah, I'm in full agreement with superbatfish here. This remains the most concisely, unambiguously, and humorously phrased variant of a question guaranteed to invite confusion and ambiguity. I mean:
"I can abuse CPython implementation details."
C'mon! That's awesome. superbatfish should be praised – not chastised – for the Pythonesque tongue-in-cheek.– Cecil Curry
Sep 3 '16 at 5:53