[Python-checkins] r80605 - python/trunk/Doc/whatsnew/2.7.rst

Nick Coghlan ncoghlan at gmail.com
Thu Apr 29 12:11:22 CEST 2010


andrew.kuchling wrote:
> +When running a module using the interpreter's :option:`-m` switch,
> +``sys.argv[0]`` will now be set to the string ``'-m'`` while the
> +module is being imported.  This will let modules determine when
> +they're being executed using :option:`-m`.  (Suggested by Michael
> +Foord; implemented by Nick Coghlan; :issue:`8202`.)

This isn't quite accurate. The patch only affects the value of
sys.argv[0] while the module to execute is being located. Most notably
(and what Michael was interested in), it will now be set to "-m"
(instead of "-c") when the __init__ code is executed for parent packages
of the module to be executed.

By the time the module itself is running, sys.argv[0] will have been
replaced with the value of __file__.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-checkins mailing list