I want IPython or the Python interpreter to auto-load a module when I start them.
Is it possible?
For example when I start IPython:
$ ipython
...
>>> from __future__ import division
>>> from mymodule import *
In [1]:
Something like SymPy's live shell found in the tutorial pages.
Automatically add import statementsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. In the Python section, configure automatic imports: Select Show import popup to automatically display an import popup when tying the name of a class that lacks an import statement.
To load the default version of Python module, use module load python . To select a particular software version, use module load python/version . For example, use module load python/3.5 to load the latest version of Python 3.5. After the module is loaded, you can run the interpreter by using the command python .
The rules are quite simple: the same module is evaluated only once, in other words, the module-level scope is executed just once. If the module, once evaluated, is imported again, it's second evaluation is skipped and the resolved already exports are used.
Have a .pythonstartup
in your home directory and load modules there and point PYTHONSTARTUP
env to that file.
Python commands in that file are executed before the first prompt is displayed in interactive mode.
I use it for enabling command line completion in python interpreter shell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With