3

I was wondering the purpose of runpy module in Python and how does it help in day to day development of the Python user community?

Can someone please explain the necessity, usage and advantages of runpy module in python?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
thirstylad
  • 357
  • 5
  • 12
  • 1
    http://legacy.python.org/dev/peps/pep-0338/, http://legacy.python.org/dev/peps/pep-0366/, https://docs.python.org/2/library/runpy.html Anything *more specific* that isn't clear from those? As it stands your question is rather broad. – Martijn Pieters May 13 '14 at 11:27
  • Generally speaking, `runpy` is an implementation detail you don't have to worry about unless you are a Python maintainer or have to debug running a module as a script. – Martijn Pieters May 13 '14 at 11:28
  • Even as a module or package developer, all you normally need to know about `runpy` is documented under the [`-m` command line switch](https://docs.python.org/2/using/cmdline.html#cmdoption-m) instead. – Martijn Pieters May 13 '14 at 11:29

1 Answers1

6

The docs say:

The runpy module is used to locate and run Python modules without importing them first. Its main use is to implement the -m command line switch that allows scripts to be located using the Python module namespace rather than the filesystem.

You can run a python module like this:

python -m SimpleHTTPServer 8000

The runpy module enables this functionality. It may not be useful outside of this context.

Constantinius
  • 34,183
  • 8
  • 77
  • 85