Expert Python Programming(Third Edition)
上QQ阅读APP看书,第一时间看更新

Setting up the PYTHONSTARTUP environment variable

If you are running Linux or macOS, the simplest way is to create the startup script in your home folder. Then, link it with a PYTHONSTARTUP environment variable that's been set in the system shell startup script. For example, Bash and Korn shell use the .profile file, where you can insert a line, as follows:

export PYTHONSTARTUP=~/.pythonstartup

If you are running Windows, it is easy to set a new environment variable as an administrator in the system preferences, and save the script in a common place instead of using a specific user location.

Writing on the PYTHONSTARTUP script may be a good exercise, but creating a good custom shell all alone is a challenge that only a few can find time for. Fortunately, there are a few custom Python shell implementations that immensely improve the experience of interactive sessions in Python.