Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41460 > unrolled thread

The usage of -m option of python

Started byPeng Yu <pengyu.ut@gmail.com>
First post2013-03-18 16:17 -0500
Last post2013-03-27 18:06 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  The usage of -m option of python Peng Yu <pengyu.ut@gmail.com> - 2013-03-18 16:17 -0500
    Re: The usage of -m option of python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-19 07:06 +0000
    Re: The usage of -m option of python Tom P <werotizy@freent.dd> - 2013-03-27 18:06 +0100

#41460 — The usage of -m option of python

FromPeng Yu <pengyu.ut@gmail.com>
Date2013-03-18 16:17 -0500
SubjectThe usage of -m option of python
Message-ID<mailman.3476.1363641451.2939.python-list@python.org>
Hi,

I don't quite understand how -m option is used. And it is difficult to
search for -m in google. Could anybody provide me with an example on
how to use this option? Thanks!

       -m module-name
              Searches sys.path for the named module and runs the
corresponding .py file as a script.

-- 
Regards,
Peng

[toc] | [next] | [standalone]


#41479

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-03-19 07:06 +0000
Message-ID<51480e59$0$6599$c3e8da3$5496439d@news.astraweb.com>
In reply to#41460
On Mon, 18 Mar 2013 16:17:27 -0500, Peng Yu wrote:

> Hi,
> 
> I don't quite understand how -m option is used. And it is difficult to
> search for -m in google. Could anybody provide me with an example on how
> to use this option? Thanks!
> 
>        -m module-name
>               Searches sys.path for the named module and runs the
> corresponding .py file as a script.


You use it to run a python module or package as a script, without caring 
whether it is a .py file, a .pyc file, a package, compressed in a zip 
file, a module written in C inside a .dll or .so file, or caring exactly 
where it is.

python -m module arguments

is conceptually like:

* launch Python
* insert arguments into sys.argv
* import module
* run it as a script
* exit


So long as the module is *somewhere* on your PYTHONPATH, -m will find it 
and run it. Whether it does something useful or not will depend on the 
module.

Here is one example of a module written to be callable as a script:

[steve@ando ~]$ python -m timeit -s "x = [3, 5, 2, 8, 1, 9, 7]" "x.sort()"
1000000 loops, best of 3: 0.451 usec per loop


Notice that I did not need to worry about where the timeit module 
actually lives on disk. All I needed to know is that it was somewhere in 
the standard library.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#42019

FromTom P <werotizy@freent.dd>
Date2013-03-27 18:06 +0100
Message-ID<argn7tFobh0U2@mid.individual.net>
In reply to#41460
On 03/18/2013 10:17 PM, Peng Yu wrote:
> Hi,
>
> I don't quite understand how -m option is used. And it is difficult to
> search for -m in google. Could anybody provide me with an example on
> how to use this option? Thanks!
>
>         -m module-name
>                Searches sys.path for the named module and runs the
> corresponding .py file as a script.
>

The most practical use I know is to run the debug program..
python -mpdb yourprogramm.py arguments..


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web