【问题标题】:Is there a way we can change the working directory of Python (IDLE) permanently?有没有办法永久更改 Python (IDLE) 的工作目录?
【发布时间】:2018-01-22 16:07:02
【问题描述】:

我正在使用 Python Enthought Canopy。每次启动编辑器时,我都必须通过键入代码来更改工作目录:

import os

os.chdir('C:/Users/Name/Canopy/scripts')

这很乏味,因为在我退出编辑器并重新开始后,目录都被重置了。 有没有办法可以更改默认工作目录,或更改 Canopy 的配置文件,以便每次在编码之前运行设置?

【问题讨论】:

标签: python-3.x directory canopy


【解决方案1】:

1) Canopy 的 GUI 不是 IDLE。

2) 由于这是 ipython 并且可以访问 ipython 魔法,因此您可以直接键入 cd ~/Canopy/scripts 而无需导入。

3) 但我猜您在编辑器中至少打开了一个脚本。因此,您可能更愿意将目录与编辑器保持同步,请参阅http://docs.enthought.com/canopy/2.1/quick-start/code_editor.html#change-directory

4) 综上所述,是的,您可以在 ipython 启动时运行任意代码。见Ipython Notebook: Default Initialization Python Code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    相关资源
    最近更新 更多