5

What happens behind the scenes when we invoke the python prompt?

I am more interested in understanding how do the methods/functions like print, import and the likes load up in the interpreter?

EDIT: Some clarification on my question:
When we type python on our unix prompt/windows console and Hit enter, what are the libraries that get loaded. My specific interest is as to how the keywords like print and import are made available to the user.

sidhshar
  • 1,063
  • 1
  • 10
  • 18
  • 1
    Neither `print` nor `import` is a function or a method in Python 2.x. And I don't really understand your question. Is there something you would like to achieve? – Sven Marnach Jan 19 '11 at 13:01
  • `help` and `quit`, OTOH, are added on initialization and that's a story worth telling... – TryPyPy Jan 19 '11 at 13:06
  • @Sven Marnach: The end of the question is strangely written, it seems to me (but english isn't my mother language). However, it's clear that he wants to ""understand"" , not to 'achieve' something. – eyquem Jan 19 '11 at 13:43

2 Answers2

5

Like you , I am very interested by the underlying mechanisms of Python. I think you'll love this series: http://tech.blog.aknin.name/category/my-projects/pythons-innards/

eyquem
  • 26,771
  • 7
  • 38
  • 46
4

There are too many levels to that question. Here's a very rough sketch.

There's the whole C-level interpreter initialization, a bunch of in-the-interpreter tasks, reading the environment and options, customization of the interpreter session. All that defines what you see when you run python.

I know there's a good description of the whole process somewhere.

TryPyPy
  • 6,214
  • 5
  • 35
  • 63
  • Thank you for the 'what you see' link. The other links are too 'roughly' informative to be easyly exploited. General overwiews and deep explanations as Yaniv Aknin's and Kristján Valur's ones are necessary for basic programmers as I am. – eyquem Jan 19 '11 at 13:56