Modifying interactive interpreter startup
As mentioned in the Working with environment variables recipe, the PYTHONSTARTUP
environment variable can be set to point to a file that contains commands that run prior to the Python interpreter starting up. This functionality is similar to .profile
on *NIX shells.
As this startup file is only examined when interactive mode is used, there is no need to worry about trying to set configurations for running scripts (though later on we will show how to include the startup file in a script). The commands in this file are executed within the same namespace as the interactive interpreter, so there is no need to qualify functions or other imports with dot-nomenclature. This file is also responsible for making changes to interactive prompts: >>>
(sys.ps1
) and ...
(sys.ps2
).
How to do it...
- To read an additional startup file from the current directory, the following example command shows how to code it in the global startup file (
read_startup.py
):
...