dub*_*uga 3 python shell function ipython
我刚刚玩过IPython.目前我想知道如何在函数中运行带有python变量的shell命令.例如:
def x(go):
return !ls -la {go}
x("*.rar")
Run Code Online (Sandbox Code Playgroud)
这给了我"sh:1:语法错误:文件结束意外".有谁可以给我一个线索,让我的"x"函数调用像ls -la*.rar这样的?我的工作目录中有*.rar文件.
Rainer,提前谢谢你
如果查看history命令输出,您将看到调用外部程序ipython使用_ip.system方法.
因此,这应该适合你:
def x(go):
return _ip.system("ls -la {0}".format(go))
Run Code Online (Sandbox Code Playgroud)
但请注意,在ipython之外你应该使用subprocess.Popen.