@@ -108,63 +108,15 @@ example, take a look at this :keyword:`if` statement::
108108 Be careful not to fall off!
109109
110110
111+ For more on interactive mode, see :ref: `tut-interac `.
112+
113+
111114.. _tut-interp :
112115
113116The Interpreter and Its Environment
114117===================================
115118
116119
117- .. _tut-error :
118-
119- Error Handling
120- --------------
121-
122- When an error occurs, the interpreter prints an error message and a stack trace.
123- In interactive mode, it then returns to the primary prompt; when input came from
124- a file, it exits with a nonzero exit status after printing the stack trace.
125- (Exceptions handled by an :keyword: `except ` clause in a :keyword: `try ` statement
126- are not errors in this context.) Some errors are unconditionally fatal and
127- cause an exit with a nonzero exit; this applies to internal inconsistencies and
128- some cases of running out of memory. All error messages are written to the
129- standard error stream; normal output from executed commands is written to
130- standard output.
131-
132- Typing the interrupt character (usually Control-C or DEL) to the primary or
133- secondary prompt cancels the input and returns to the primary prompt. [# ]_
134- Typing an interrupt while a command is executing raises the
135- :exc: `KeyboardInterrupt ` exception, which may be handled by a :keyword: `try `
136- statement.
137-
138-
139- .. _tut-scripts :
140-
141- Executable Python Scripts
142- -------------------------
143-
144- On BSD'ish Unix systems, Python scripts can be made directly executable, like
145- shell scripts, by putting the line ::
146-
147- #! /usr/bin/env python
148-
149- (assuming that the interpreter is on the user's :envvar: `PATH `) at the beginning
150- of the script and giving the file an executable mode. The ``#! `` must be the
151- first two characters of the file. On some platforms, this first line must end
152- with a Unix-style line ending (``'\n' ``), not a Windows (``'\r\n' ``) line
153- ending. Note that the hash, or pound, character, ``'#' ``, is used to start a
154- comment in Python.
155-
156- The script can be given an executable mode, or permission, using the
157- :program: `chmod ` command::
158-
159- $ chmod +x myscript.py
160-
161- On Windows systems, there is no notion of an "executable mode". The Python
162- installer automatically associates ``.py `` files with ``python.exe `` so that
163- a double-click on a Python file will run it as a script. The extension can
164- also be ``.pyw ``, in that case, the console window that normally appears is
165- suppressed.
166-
167-
168120.. _tut-source-encoding :
169121
170122Source Code Encoding
@@ -207,63 +159,3 @@ supported. To display all these characters properly, your editor must recognize
207159that the file is UTF-8, and it must use a font that supports all the characters
208160in the file.
209161
210-
211- .. _tut-startup :
212-
213- The Interactive Startup File
214- ----------------------------
215-
216- When you use Python interactively, it is frequently handy to have some standard
217- commands executed every time the interpreter is started. You can do this by
218- setting an environment variable named :envvar: `PYTHONSTARTUP ` to the name of a
219- file containing your start-up commands. This is similar to the :file: `.profile `
220- feature of the Unix shells.
221-
222- .. XXX This should probably be dumped in an appendix, since most people
223- don't use Python interactively in non-trivial ways.
224-
225- This file is only read in interactive sessions, not when Python reads commands
226- from a script, and not when :file: `/dev/tty ` is given as the explicit source of
227- commands (which otherwise behaves like an interactive session). It is executed
228- in the same namespace where interactive commands are executed, so that objects
229- that it defines or imports can be used without qualification in the interactive
230- session. You can also change the prompts ``sys.ps1 `` and ``sys.ps2 `` in this
231- file.
232-
233- If you want to read an additional start-up file from the current directory, you
234- can program this in the global start-up file using code like ``if
235- os.path.isfile('.pythonrc.py'): execfile('.pythonrc.py') ``. If you want to use
236- the startup file in a script, you must do this explicitly in the script::
237-
238- import os
239- filename = os.environ.get('PYTHONSTARTUP')
240- if filename and os.path.isfile(filename):
241- execfile(filename)
242-
243-
244- .. _tut-customize :
245-
246- The Customization Modules
247- -------------------------
248-
249- Python provides two hooks to let you customize it: :mod: `sitecustomize ` and
250- :mod: `usercustomize `. To see how it works, you need first to find the location
251- of your user site-packages directory. Start Python and run this code:
252-
253- >>> import site
254- >>> site.getusersitepackages()
255- '/home/user/.local/lib/python2.7/site-packages'
256-
257- Now you can create a file named :file: `usercustomize.py ` in that directory and
258- put anything you want in it. It will affect every invocation of Python, unless
259- it is started with the :option: `-s ` option to disable the automatic import.
260-
261- :mod: `sitecustomize ` works in the same way, but is typically created by an
262- administrator of the computer in the global site-packages directory, and is
263- imported before :mod: `usercustomize `. See the documentation of the :mod: `site `
264- module for more details.
265-
266-
267- .. rubric :: Footnotes
268-
269- .. [# ] A problem with the GNU Readline package may prevent this.
0 commit comments