rest25/library/codeop.rst => rest262/library/codeop.rst
2:mod:`codeop` --- Compile Python code
3=====================================
4
5.. module:: codeop
6   :synopsis: Compile (possibly incomplete) Python code.
7.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
8.. sectionauthor:: Michael Hudson <mwh@python.net>
9
n10- 
11-.. % LaTeXed from excellent doc-string.
12- 
13-The :mod:`codeop` module provides utilities upon which the Python read-eval-
10+The :mod:`codeop` module provides utilities upon which the Python
14-print loop can be emulated, as is done in the :mod:`code` module.  As a result,
11+read-eval-print loop can be emulated, as is done in the :mod:`code` module.  As
15-you probably don't want to use the module directly; if you want to include such
12+a result, you probably don't want to use the module directly; if you want to
16-a loop in your program you probably want to use the :mod:`code` module instead.
13+include such a loop in your program you probably want to use the :mod:`code`
14+module instead.
17
18There are two parts to this job:
19
20#. Being able to tell if a line of input completes a Python  statement: in
21   short, telling whether to print '``>>>``' or '``...``' next.
22
23#. Remembering which future statements the user has entered, so  subsequent
24   input can be compiled with these in effect.
25
26The :mod:`codeop` module provides a way of doing each of these things, and a way
27of doing them both.
28
29To do just the former:
30
n31- 
32.. function:: compile_command(source[, filename[, symbol]])
33
34   Tries to compile *source*, which should be a string of Python code and return a
35   code object if *source* is valid Python code. In that case, the filename
36   attribute of the code object will be *filename*, which defaults to
37   ``'<input>'``. Returns ``None`` if *source* is *not* valid Python code, but is a
38   prefix of valid Python code.
39
40   If there is a problem with *source*, an exception will be raised.
41   :exc:`SyntaxError` is raised if there is invalid Python syntax, and
42   :exc:`OverflowError` or :exc:`ValueError` if there is an invalid literal.
43
44   The *symbol* argument determines whether *source* is compiled as a statement
n45-   (``'single'``, the default) or as an expression (``'eval'``).  Any other value
n42+   (``'single'``, the default) or as an :term:`expression` (``'eval'``).  Any
46-   will cause :exc:`ValueError` to  be raised.
43+   other value will cause :exc:`ValueError` to  be raised.
47
t45+   .. warning::
46+ 
48-   **Caveat:** It is possible (but not likely) that the parser stops parsing with a
47+      It is possible (but not likely) that the parser stops parsing with a
49-   successful outcome before reaching the end of the source; in this case, trailing
48+      successful outcome before reaching the end of the source; in this case,
50-   symbols may be ignored instead of causing an error.  For example, a backslash
49+      trailing symbols may be ignored instead of causing an error.  For example,
51-   followed by two newlines may be followed by arbitrary garbage.  This will be
50+      a backslash followed by two newlines may be followed by arbitrary garbage.
52-   fixed once the API for the parser is better.
51+      This will be fixed once the API for the parser is better.
53
54
55.. class:: Compile()
56
57   Instances of this class have :meth:`__call__` methods identical in signature to
58   the built-in function :func:`compile`, but with the difference that if the
59   instance compiles program text containing a :mod:`__future__` statement, the
60   instance 'remembers' and compiles all subsequent program texts with the
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op