在 site-packages\spyderlib
目录中搜索关键字 %run
后,我发现了构建 %run
命令的方法(在 site-packages\spyderlib\plugins\ipythonconsole.py
中):
def run_script_in_current_client(self, filename, wdir, args, debug):
"""Run script in current client, if any"""
norm = lambda text: remove_backslashes(to_text_string(text))
client = self.get_current_client()
if client is not None:
if client.kernel_widget_id is not None:
line = "%s('%s'" % ('debugfile' if debug else 'runfile',
norm(filename))
if args:
line += ", args='%s'" % norm(args)
if wdir:
line += ", wdir='%s'" % norm(wdir)
line += ")"
else:
line = "%run "
if debug:
line += "-d "
line += "\"%s\"" % to_text_string(filename)
if args:
line += " %s" % norm(args)
self.execute_python_code(line)
self.visibility_changed(True)
self.raise_()
else:
QMessageBox.warning(self, _('Warning'),
_("No IPython console is currently available to run <b>%s</b>."
"<br><br>Please open a new one and try again."
) % osp.basename(filename), QMessageBox.Ok)
我在
else: # External kernels, use %run
后添加了以下代码以转换路径:
localpath = "Z:\wk"
remotepath = "/mnt/sdb1/wk"
if localpath in filename:
filename = filename.replace(localpath, remotepath)
filename = filename.replace("\\", "/")
当我按下 F5 键时,它会在远程计算机上运行文件。我使用的是 Spyder 2.3.9
,并且将 Samba 共享映射到了 Z: 驱动器。