Why and how "there is only one way to do something"?
Delaney, Timothy (Tim)
tdelaney at avaya.com
Thu Dec 15 16:29:29 EST 2005
Simon Brunning wrote:
> On 12/15/05, Steve Holden <steve at holdenweb.com> wrote:
>> Aahz wrote:
>>> python -c 'import this'
>>
>> Faster:
>>
>> python -m this
>
> So, there's two ways to do it. ;-)
It's actually a perfect example of an "new" one-obvious-way replacing an
old way (or rather, couple of ways).
In fact, `python -m <module>` is not an exact replacement for `python -c
'import this'`. The -m invocation sets the specified module as the
__main__ module, and so code in:
if __name__ == '__main__':
will run. The -c import invocation does not set the specified module as
the __main__ module.
The -m semantics are more normally what you want, and so -m has become
the one obvious way to do it (assuming Python 2.4 and up).
Tim Delaney
More information about the Python-list
mailing list