从 bash 将参数传递给 python 函数

Siv*_*bbu 5 python bash shell

我正在尝试以下命令

 python -c 'import sample; sample.Functionname()'
 python -c 'import sample; sample.printFxn("helloWorld")'
Run Code Online (Sandbox Code Playgroud)

这两个都工作得很好,但是当我传递一个变量作为参数时,我收到以下错误。

 File "<string>", line 1 import sample; sample.printFxn($filename) SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

将变量作为参数从 bash 传递给 python 函数的正确方法是什么?

che*_*ner 7

不要将字符串变量插入到命令中;将值作为参数传递给 Python 脚本。

python -c 'import sys, sample; sample.printFxn(sys.argv[1])' "$fileName"
Run Code Online (Sandbox Code Playgroud)