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

Python 将变量传递到Spyder中的命令行,python,python-3.x,git,spyder,Python,Python 3.x,Git,Spyder,我正试图在Spyder中创建一个自动提交的函数,因为我经常键入以下内容: !git init !git add myfilename.py !git commit -m "my commit comment" 但要作为函数工作,我需要能够传递为函数参数输入的文件名,我会得到一个不足为奇的错误:致命:pathspec“file”与任何文件都不匹配 def gitCommit(*files, commit = "Place Commit Comment Here"): !git init

我正试图在Spyder中创建一个自动提交的函数,因为我经常键入以下内容:

!git init
!git add myfilename.py
!git commit -m "my commit comment"
但要作为函数工作,我需要能够传递为函数参数输入的文件名,我会得到一个不足为奇的错误:致命:pathspec“file”与任何文件都不匹配

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

我不知道怎样才能逃过这场战争!代码中明显无法识别变量文件的方面执行此操作时,它应该可以工作:-

!!git添加$file

我刚刚检查了文件

别名扩展Python变量,就像使用!或 do:所有前缀为“$”的表达式都将展开。详情请参阅 语义规则,见PEP-215:


非常好,谢谢。有趣的是,它也在引用中起作用,我花了一段时间才让评论起作用,因为我猜不到这一点。comment=在此处放置Commit comment!git commit-m$comment