我想用 pydev 在 python 中编写一些脚本。
我遇到的问题是我无法在脚本所在的项目目录中启动控制台,控制台在 pydev/aptana 文件夹(aptana 文件夹中的某个位置)中启动。
我可以通过将以下代码添加到我的脚本中来解决这些问题:
import os
import inspect
filename = inspect.getframeinfo(inspect.currentframe()).filename
curpath = os.path.dirname(os.path.abspath(filename))
os.chdir(curpath)
Does somebody know how to change the directory of the console to the project position path automatically when started over the pydev Ctrl+Alt+Enter way ?
--EDIT--
如果有人更喜欢的话,这是我自己的解决方案:
import sys; print('%s %s' % (sys.executable or sys.platform, sys.version)) import os;os.chdir([p for p in os.environ['PYTHONPATH'].split(os.pathsep) if ('Aptana Workspace' in p)][0]) pwd()
我将以下内容添加到“首选项”->“PyDev”->“交互式控制台”->“初始命令”中的预执行脚本中:
import os
import inspect
__old_runfile = runfile
def runfile(file):
curpath = os.path.dirname(os.path.abspath(file))
os.chdir(curpath)
__old_runfile(file)
This overrides the default runfile command and causes Ctrl+Alt+Enter to change to the directory of the script upon loading it.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)