Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 1 | \section{\module{py_compile} --- |
| 2 | Compile Python source files} |
| 3 | |
Fred Drake | 4756bb3 | 1998-08-11 15:46:25 +0000 | [diff] [blame] | 4 | % Documentation based on module docstrings, by Fred L. Drake, Jr. |
| 5 | % <fdrake@acm.org> |
| 6 | |
Fred Drake | 4756bb3 | 1998-08-11 15:46:25 +0000 | [diff] [blame] | 7 | \declaremodule[pycompile]{standard}{py_compile} |
| 8 | |
| 9 | \modulesynopsis{Compile Python source files to byte-code files.} |
| 10 | |
| 11 | |
| 12 | \indexii{file}{byte-code} |
| 13 | The \module{py_compile} module provides a single function to generate |
| 14 | a byte-code file from a source file. |
| 15 | |
| 16 | Though not often needed, this function can be useful when installing |
| 17 | modules for shared use, especially if some of the users may not have |
| 18 | permission to write the byte-code cache files in the directory |
| 19 | containing the source code. |
| 20 | |
| 21 | |
| 22 | \begin{funcdesc}{compile}{file\optional{, cfile\optional{, dfile}}} |
| 23 | Compile a source file to byte-code and write out the byte-code cache |
| 24 | file. The source code is loaded from the file name \var{file}. The |
| 25 | byte-code is written to \var{cfile}, which defaults to \var{file} |
| 26 | \code{+} \code{'c'} (\code{'o'} if optimization is enabled in the |
| 27 | current interpreter). If \var{dfile} is specified, it is used as |
| 28 | the name of the source file in error messages instead of \var{file}. |
| 29 | \end{funcdesc} |
| 30 | |
| 31 | |
| 32 | \begin{seealso} |
| 33 | \seemodule{compileall}{Utilities to compile all Python source files |
| 34 | in a directory tree.} |
| 35 | \end{seealso} |