【问题标题】:command line ipython with --pylab + more imports带有 --pylab + 更多导入的命令行 ipython
【发布时间】:2020-11-12 11:06:20
【问题描述】:

--pylab 命令行参数使ipython 成为我经常使用的终端窗口中快速但功能强大的计算器。有没有办法通过命令行将其他有用的导入传递给ipython,例如

from scipy.constants import * 

哪个使用起来更方便?

【问题讨论】:

    标签: python scipy ipython


    【解决方案1】:

    如果您安装了sympy,您将获得以ipython 开头并带有sympy 导入的脚本。这个脚本可能会给你一些想法。

    2119:~/mypy$ which isympy
    /usr/local/bin/isympy
    2119:~/mypy$ cat /usr/local/bin/isympy
    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    import re
    import sys
    from isympy import main
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
        sys.exit(main())
    

    配置文件中可能还有一个地方可以指定导入,但我最近没有探索过。

    或者使用'-c'选项:

    2128:~/mypy$ ipython3 --pylab -c "from scipy import constants" -i
    Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.
    Using matplotlib backend: Qt5Agg
    
    In [1]: constants.bar
    Out[1]: 100000.0
    

    【讨论】:

    • 我猜诀窍是最后的-i 开关。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    相关资源
    最近更新 更多