Google colaboratory 在Colab中运行带有参数的python文件

Google colaboratory 在Colab中运行带有参数的python文件,google-colaboratory,Google Colaboratory,我正在尝试在Colab中运行python(test.py)文件。该文件需要输入一些参数,例如“--epoch”、“--class_file”。我所做的是: !python test.py "--epoch" 100 "--class_file" class_file #class_file is a path string 参数解析后,class\u文件不会被解释为预期的路径字符串,而是类似于class file=“class\u文件”的字符串。这是怎

我正在尝试在Colab中运行python(
test.py
)文件。该文件需要输入一些参数,例如“--epoch”、“--class_file”。我所做的是:

!python test.py "--epoch" 100 "--class_file" class_file
#class_file is a path string 

参数解析后,
class\u文件
不会被解释为预期的路径字符串,而是类似于
class file=“class\u文件”
的字符串。这是怎么发生的?

将参数变量放在一个大括号中
{}
!python test.py”--epoch“100”--class_文件“{class_文件}


请参阅一篇文章,将参数变量放在一个大括号中。
{}
!python test.py”--epoch“100”--class_文件“{class_文件}


请参阅帖子

如果从命令中删除所有引号,会发生什么情况?这没有帮助。仍然给出错误:FileNotFoundError:[Errno 2]没有这样的文件或目录:“classes\u file”如果从命令中删除所有引号会发生什么?这没有帮助。仍然给出错误:FileNotFoundError:[Errno 2]没有这样的文件或目录:“classes\u file”