The --pylab
command line arguments makes ipython
a quick but powerful calculator in the terminal window which I use quite often. Is there a way to pass other useful imports to ipython
via command line, such as
JavaScript
x
2
1
from scipy.constants import *
2
which makes it even more convenient to use?
Advertisement
Answer
If you have installed sympy
you get script that starts ipython
with sympy
imports. This script may give you ideas.
JavaScript
1
12
12
1
2119:~/mypy$ which isympy
2
/usr/local/bin/isympy
3
2119:~/mypy$ cat /usr/local/bin/isympy
4
#!/usr/bin/python3
5
# -*- coding: utf-8 -*-
6
import re
7
import sys
8
from isympy import main
9
if __name__ == '__main__':
10
sys.argv[0] = re.sub(r'(-script.pyw|.exe)?$', '', sys.argv[0])
11
sys.exit(main())
12
There may also be a place in the profile to specify imports, but I haven’t explored that recently.
Or use the ‘-c’ option:
JavaScript
1
9
1
2128:~/mypy$ ipython3 --pylab -c "from scipy import constants" -i
2
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
3
Type 'copyright', 'credits' or 'license' for more information
4
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.
5
Using matplotlib backend: Qt5Agg
6
7
In [1]: constants.bar
8
Out[1]: 100000.0
9