简体   繁体   中英

How to make a script execute just after python shell starts and before customuer's input?

In Pythonxy I can edit some python scripts in an pre-defined folder so that they will be executed (or import? I don't know). For example, if I put a script in that folder:

import numpy as np
import scipy as sp

Then after I enter python shell, I can conveniently use np and sp as quick references.

Now the problem is, how can I use such technique without Pythonxy's support in standard python shell? Can I write a script to handle pre import? I think it will be very useful.

You can do this by setting up a python startup file, and set PYTHONSTARTUP variable to that file. In the startup file, just write

import numpy as np
import scipy as sp

Then, every time you enter python shell, it will automatically import the above modules.

Here is an example. Installing pythonstartup file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM