GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.python.org — 16. Appendix 16. Appendix¶16.1. Interactive Mode¶16.1.1. Error Handling¶When an error occurs, the interpreter prints an error message and a stack trace.
In interactive mode, it then returns to the primary prompt; when input came from
a file, it exits with a nonzero exit status after printing the stack trace.
(Exceptions handled by an Typing the interrupt character (usually Control-C or Delete) to the primary or
secondary prompt cancels the input and returns to the primary prompt. [1]
Typing an interrupt while a command is executing raises the
16.1.2. Executable Python Scripts¶On BSD’ish Unix systems, Python scripts can be made directly executable, like shell scripts, by putting the line #!/usr/bin/env python3.5
(assuming that the interpreter is on the user’s The script can be given an executable mode, or permission, using the chmod command. $ chmod +x myscript.py On Windows systems, there is no notion of an “executable mode”. The Python
installer automatically associates 16.1.3. The Interactive Startup File¶When you use Python interactively, it is frequently handy to have some standard
commands executed every time the interpreter is started. You can do this by
setting an environment variable named This file is only read in interactive sessions, not when Python reads commands
from a script, and not when If you want to read an additional start-up file from the current directory, you
can program this in the global start-up file using code like import os filename = os.environ.get('PYTHONSTARTUP') if filename and os.path.isfile(filename): with open(filename) as fobj: startup_file = fobj.read() exec(startup_file) 16.1.4. The Customization Modules¶Python provides two hooks to let you customize it: sitecustomize and usercustomize. To see how it works, you need first to find the location of your user site-packages directory. Start Python and run this code: >>> import site >>> site.getusersitepackages() '/home/user/.local/lib/python3.5/site-packages' Now you can create a file named sitecustomize works in the same way, but is typically created by an
administrator of the computer in the global site-packages directory, and is
imported before usercustomize. See the documentation of the Footnotes
©
Copyright
2001-2026, Python Software Foundation.
This page is licensed under the Python Software Foundation License Version 2. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License. See History and License for more information. The Python Software Foundation is a non-profit corporation. Please donate. Last updated on Oct 26, 2026 (16:21 UTC). Found a bug? Created using Sphinx 7.2.6. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |