http://www.python.org/dev/peps/pep-0366/
http://www.python.org/dev/peps/pep-0338/
The Runpy module is used to locate and run Python modules without importing. Its main ' to implement the-m ' command line switch ' that allows ' scripts to be located using the Python module Namespac E rather than the filesystem.
The Runpy module is used to locate and execute the module when the Python module is not being import. The main purpose is to implement the results of the command line-m execution of the Python module, but in the script rather than the file system.
Runpy one on two functions:
Runpy.run_module (Mod_name, Init_globals=none, Run_name=none, Alter_sys=false)
Runs the specified module code and returns the global Dictionary of the module.
Example:
Import Runpy
from pprint import pprint
ttt = runpy.run_module (' Classproperty ', alter_sys=true)
Pprint (TTT)
Runpy.run_path (File_path, Init_globals=none, Run_name=none)
Executes the specified script file and returns the module global dictionary.
Example:
First write a script
$ cat a.py
print ' iiiiiiiiiiiiinnnnnnnnnnnnnn a%s '%bb
print __name__
print __file__
print __loader__< C4/>print __package__
If __name__ = = ' __main__ ':
print ' in __main__ '
And then
Import runpy from
pprint import pprint
bb = ' UUU '
GGG = Runpy.run_path (' a.py ', init_globals={' BB ': bb}, Run_ Name= ' __main__ ')
print ' ===================== '
pprint (GGG)
Init_globals is a dictionary passed to the running module (file), and there are four global variables that are bound to pass through: __name__, __file__, __loader__ and __package__