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):
if os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read()
While the startup file is only looked at for interactive mode, it can be referenced within a script. startup_script.py shows how to do this:
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)