Setting the working directory of IPython Shell to that of the python file being executed in Canopy

本秂侑毒 提交于 2019-12-06 06:18:34
punchagan

This is a feature that is on our list of features, but quite low on priority. Canopy provides a right click context menu option to switch to the currently active editor's directory (see this).

Also, as a temporary work-around, you could use the following macro to get your job done.

# -*- coding: utf-8 -*-

def run():
    code_task = get_active_task()

    from os.path import dirname

    def change_directory():
        code_editor = code_task.active_editor
        if not code_editor:
            return
        python_pane = code_task.python_pane
        active_dir = dirname(code_editor.obj.path)
        python_pane.execute_command(u'cd %s\n' % active_dir)

    code_task.on_trait_change(change_directory, 'active_editor') 

Note: You'll have to run this macro, each time you have closed and reopened the editor window.

See 1 and 2 for instructions on how to create a macro and for more information about macros in Canopy.

You can use cd inside of iPython. cd stands for change directory

> cd /home/username/my_otherdirectory

Right click on python tab in Canopy and from menu select 'Keep Directory Synced to Editor'. It will set directory containing your source file as your current working directory.You can set any directory as your working directory by selecting 'Change Working Directory' from right click menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!