summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/reference%2Ftoplevel_components.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/python~3.12/reference%2Ftoplevel_components.html')
-rw-r--r--devdocs/python~3.12/reference%2Ftoplevel_components.html16
1 files changed, 16 insertions, 0 deletions
diff --git a/devdocs/python~3.12/reference%2Ftoplevel_components.html b/devdocs/python~3.12/reference%2Ftoplevel_components.html
new file mode 100644
index 00000000..158bbb99
--- /dev/null
+++ b/devdocs/python~3.12/reference%2Ftoplevel_components.html
@@ -0,0 +1,16 @@
+ <span id="top-level"></span><h1> Top-level components</h1> <p id="index-0">The Python interpreter can get its input from a number of sources: from a script passed to it as standard input or as program argument, typed in interactively, from a module source file, etc. This chapter gives the syntax used in these cases.</p> <section id="complete-python-programs"> <span id="programs"></span><h2>
+<span class="section-number">9.1. </span>Complete Python programs</h2> <span class="target" id="index-1"></span><p id="index-2">While a language specification need not prescribe how the language interpreter is invoked, it is useful to have a notion of a complete Python program. A complete Python program is executed in a minimally initialized environment: all built-in and standard modules are available, but none have been initialized, except for <a class="reference internal" href="../library/sys#module-sys" title="sys: Access system-specific parameters and functions."><code>sys</code></a> (various system services), <a class="reference internal" href="../library/builtins#module-builtins" title="builtins: The module that provides the built-in namespace."><code>builtins</code></a> (built-in functions, exceptions and <code>None</code>) and <a class="reference internal" href="../library/__main__#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code>__main__</code></a>. The latter is used to provide the local and global namespace for execution of the complete program.</p> <p>The syntax for a complete Python program is that for file input, described in the next section.</p> <p id="index-3">The interpreter may also be invoked in interactive mode; in this case, it does not read and execute a complete program but reads and executes one statement (possibly compound) at a time. The initial environment is identical to that of a complete program; each statement is executed in the namespace of <a class="reference internal" href="../library/__main__#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code>__main__</code></a>.</p> <p id="index-4">A complete program can be passed to the interpreter in three forms: with the <a class="reference internal" href="../using/cmdline#cmdoption-c"><code>-c</code></a> <em>string</em> command line option, as a file passed as the first command line argument, or as standard input. If the file or standard input is a tty device, the interpreter enters interactive mode; otherwise, it executes the file as a complete program.</p> </section> <section id="file-input"> <span id="id1"></span><h2>
+<span class="section-number">9.2. </span>File input</h2> <p>All input read from non-interactive files has the same form:</p> <pre>
+<strong id="grammar-token-python-grammar-file_input"><span id="grammar-token-file-input"></span>file_input</strong> ::= (NEWLINE | <a class="reference internal" href="compound_stmts#grammar-token-python-grammar-statement">statement</a>)*
+</pre> <p>This syntax is used in the following situations:</p> <ul class="simple"> <li>when parsing a complete Python program (from a file or from a string);</li> <li>when parsing a module;</li> <li>when parsing a string passed to the <a class="reference internal" href="../library/functions#exec" title="exec"><code>exec()</code></a> function;</li> </ul> </section> <section id="interactive-input"> <span id="interactive"></span><h2>
+<span class="section-number">9.3. </span>Interactive input</h2> <p>Input in interactive mode is parsed using the following grammar:</p> <pre>
+<strong id="grammar-token-python-grammar-interactive_input"><span id="grammar-token-interactive-input"></span>interactive_input</strong> ::= [<a class="reference internal" href="compound_stmts#grammar-token-python-grammar-stmt_list">stmt_list</a>] NEWLINE | <a class="reference internal" href="compound_stmts#grammar-token-python-grammar-compound_stmt">compound_stmt</a> NEWLINE
+</pre> <p>Note that a (top-level) compound statement must be followed by a blank line in interactive mode; this is needed to help the parser detect the end of the input.</p> </section> <section id="expression-input"> <span id="id2"></span><h2>
+<span class="section-number">9.4. </span>Expression input</h2> <span class="target" id="index-5"></span><p id="index-6"><a class="reference internal" href="../library/functions#eval" title="eval"><code>eval()</code></a> is used for expression input. It ignores leading whitespace. The string argument to <a class="reference internal" href="../library/functions#eval" title="eval"><code>eval()</code></a> must have the following form:</p> <pre>
+<strong id="grammar-token-python-grammar-eval_input"><span id="grammar-token-eval-input"></span>eval_input</strong> ::= <a class="reference internal" href="expressions#grammar-token-python-grammar-expression_list">expression_list</a> NEWLINE*
+</pre> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/reference/toplevel_components.html" class="_attribution-link">https://docs.python.org/3.12/reference/toplevel_components.html</a>
+ </p>
+</div>