将变量传递到 Spyder 中的命令行

Pass variable into command line in Spyder

我正在尝试创建一个函数来自动执行我在 Spyder 中的提交,因为我发现自己经常输入以下内容:

!git init
!git add myfilename.py
!git commit -m "my commit comment"

但是要作为一个函数工作,我需要能够传递我为函数参数输入的文件名,我得到了一个不足为奇的错误:"fatal: pathspec 'file' did not match any files"

def gitCommit(*files, commit = "Place Commit Comment Here"):
    !git init
    for file in files:
        !git add file
    !git commit -m paste(commit)

我不确定如何转义“!”显然无法识别变量 "file"

的代码方面

这样做,它应该会起作用:-

!git add $file

我刚刚查看了文档。

Ipython Magics

Aliases expand Python variables just like system calls using ! or !! do: all expressions prefixed with ‘$’ get expanded. For details of the semantic rules, see PEP-215:...