Alexander Belopolsky wrote:
Take a look at two PEPs referenced in runpy doc, http://docs.python.org/3.1/library/runpy.html :
PEP 338 - Executing modules as scripts PEP written and implemented by Nick Coghlan. PEP 366 - Main module explicit relative imports PEP written and implemented by Nick Coghlan.
(Nick is too modest to self-reference, but these two PEPs give an excellent exposition. :-)
The PEPs don't go into the process of how we actually hook the command line up to the runpy module though - that's something you need to dig into the main.c code to really understand.
The command line documentation is also relevant since it defines the intended behaviour: http://docs.python.org/dev/using/cmdline.html#command-line
(Drop the /dev from the URL to see the defined behaviour for 2.6)