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










25














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









share|improve this question



















  • 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
















25














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









share|improve this question



















  • 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














25












25








25


2





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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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













  • 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













2 Answers
2






active

oldest

votes


















56














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





share|improve this answer
















  • 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


















7














How about platform



it gives you



platform.python_implementation()





share|improve this answer




















    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
    );



    );













    draft saved

    draft discarded


















    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









    56














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





    share|improve this answer
















    • 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















    56














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





    share|improve this answer
















    • 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













    56












    56








    56






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





    share|improve this answer












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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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












    • 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













    7














    How about platform



    it gives you



    platform.python_implementation()





    share|improve this answer

























      7














      How about platform



      it gives you



      platform.python_implementation()





      share|improve this answer























        7












        7








        7






        How about platform



        it gives you



        platform.python_implementation()





        share|improve this answer












        How about platform



        it gives you



        platform.python_implementation()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 5 '13 at 22:26









        Jakob Bowyer

        22.7k65381




        22.7k65381



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo