私信  •  关注

Honest Abe David Cournapeau

Honest Abe David Cournapeau 最近创建的主题
Honest Abe David Cournapeau 最近回复了
11 年前
回复了 Honest Abe David Cournapeau 创建的主题 » ipython评估本地目录中的文件[重复]

您可以编写自己的函数:

def xfile(afile, globalz=None, localz=None):
    with open(afile, "r") as fh:
        exec(fh.read(), globalz, localz)

如果你真的需要…

11 年前
回复了 Honest Abe David Cournapeau 创建的主题 » ipython评估本地目录中的文件[重复]

你只需要自己读取文件并执行代码。2to3电流替代

execfile("somefile.py", global_vars, local_vars)

作为

with open("somefile.py") as f:
    code = compile(f.read(), "somefile.py", 'exec')
    exec(code, global_vars, local_vars)

(编译调用不是严格需要的,但它将文件名与代码对象相关联,从而使调试变得更容易。)

见: