Help on function compile in module py_compile:
compile(file, cfile=None, dfile=None, doraise=False)
Byte-compile one Python source file to Python bytecode.
Arguments:
file: source filename
cfile: target filename; defaults to source with 'c' or 'o' appended
('c' normally, 'o' in optimizing mode, giving .pyc or .pyo)
dfile: purported filename; defaults to source (this is the filename
that will show up in error messages)
doraise: flag indicating whether or not an exception should be
raised when a compile error is found. If an exception
occurs and this flag is set to False, a string
indicating the nature of the exception will be printed,
and the function will return to the caller. If an
exception occurs and this flag is set to True, a
PyCompileError exception will be raised.
Note that it isn't necessary to byte-compile Python modules for
execution efficiency -- Python itself byte-compiles a module when
it is loaded, and if it can, writes out the bytecode to the
corresponding .pyc (or .pyo) file.
However, if a Python installation is shared between users, it is a
good idea to byte-compile all modules upon installation, since
other users may not be able to write in the source directories,
and thus they won't be able to write the .pyc/.pyo file, and then
they would be byte-compiling every module each time it is loaded.
This can slow down program start-up considerably.
See compileall.py for a script/module that uses this module to
byte-compile all installed files (or all files in selected
directories).
[baichuan@zjdw-odmz-0009 python]$ ls
adp_group_info_data adp_group_info.py db_api.py db_api.pyc dump_rmc_area_ip.py dump_rmc_tag.py
[baichuan@zjdw-odmz-0009 python]$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_compile
>>> py_compile.compile("adp_group_info.py")
>>> py_compile.compile("/home/baichuan/yxc/python/dump_rmc_tag.py")
>>> quit()
[baichuan@zjdw-odmz-0009 python]$ ls
adp_group_info_data adp_group_info.py adp_group_info.pyc db_api.py db_api.pyc dump_rmc_area_ip.py dump_rmc_tag.py dump_rmc_tag.pyc
[baichuan@zjdw-odmz-0009 python]$
Help on function compile_dir in module compileall:
compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None, quiet=0)
Byte-compile all modules in the given directory tree.
Arguments (only dir is required):
dir: the directory to byte-compile
maxlevels: maximum recursion level (default 10)
ddir: if given, purported directory name (this is the
directory name that will show up in error messages)
force: if 1, force compilation, even if timestamps are up-to-date
quiet: if 1, be quiet during compilation
[baichuan@zjdw-odmz-0009 python]$ ls
adp_group_info_data adp_group_info.py db_api.py dump_rmc_area_ip.py dump_rmc_tag.py
[baichuan@zjdw-odmz-0009 python]$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import compileall
>>> compileall.compile_dir("/home/baichuan/yxc/python/")
Listing /home/baichuan/yxc/python/ ...
Compiling /home/baichuan/yxc/python/adp_group_info.py ...
Compiling /home/baichuan/yxc/python/db_api.py ...
Compiling /home/baichuan/yxc/python/dump_rmc_area_ip.py ...
Compiling /home/baichuan/yxc/python/dump_rmc_tag.py ...
1
>>> quit()
[baichuan@zjdw-odmz-0009 python]$ ls
adp_group_info_data adp_group_info.py adp_group_info.pyc db_api.py db_api.pyc dump_rmc_area_ip.py dump_rmc_area_ip.pyc dump_rmc_tag.py dump_rmc_tag.pyc
[baichuan@zjdw-odmz-0009 python]$