Start ipython running a script

后端 未结 7 1022
暖寄归人
暖寄归人 2020-12-08 19:09

My use case is I want to initialize some functions in a file and then start up ipython with those functions defined. Is there any way to do something like

i         


        
7条回答
  •  余生分开走
    2020-12-08 19:24

    You can use ipython profiles to define startup scripts that will run every time you start ipython. A full description of profiles, is given here. You can create multiple profiles with different startup files.

    Assuming you only need one profile, and always want the same startup files every time you start ipython, you can simply modify the default profile. To do this, first find out where your ipython configuration directory is in an ipython session.:

    In [1]: import IPython
    In [2]: IPython.paths.get_ipython_dir() # As of IPython v4.0
    In [3]: print(ipython_config_dir)
    /home/johndoe/.config/ipython
    

    For this example, I am using Ubuntu Linux, and the config directory is in /home/johndoe/.config/ipython, where johndoe is the username.

    The default_profile is in the profile_default subdirectory. Put any starting scripts in profile_default/startup. In the example here, the full path would be /home/johndoe/.config/ipython/profile_default/startup.

提交回复
热议问题