如何在Google Colab中使用动态参数调用Python脚本?

发布于 2025-01-31 01:24:49 字数 373 浏览 4 评论 0原文

我正在尝试运行一个用于批次数据的Python脚本(在Google Colab中)。我尝试通过为每次运行提供不同的文件夹名称来动态保存结果。例如:

counter=counter+1
source='/myfolder/test_' + str(counter)
!python mycode.py --source source

它从字面上看对象“源”,因此它不会找到'/root/source/'之类的东西,但是如果我尝试使用:

!python mycode.py --source '/myfolder/test_' + str(counter)

它不会接受串联。有什么想法如何使该论点具有动态价值?

I'm trying to run a python script for batches of data (in Google Colab). I try to save the results dynamically by giving different folder names for each run. For example:

counter=counter+1
source='/myfolder/test_' + str(counter)
!python mycode.py --source source

It takes the object "source" literally so it wont find something like '/root/source/', but if I try using:

!python mycode.py --source '/myfolder/test_' + str(counter)

It won't accept the concatenation. Any ideas how to give that argument a dynamic value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天荒地未老 2025-02-07 01:24:49

好吧,我找到了答案。基本上,应该将其放入一个变量:

source='/myfolder/test_' + str(counter)
run = f'python mycode.py -- source {source}'
!{run}

Okay, I found an answer. Basically, it should be put into a variable:

source='/myfolder/test_' + str(counter)
run = f'python mycode.py -- source {source}'
!{run}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文