如何在 google colab 中接受输入,然后在整个代码中使用该输入(特别是在 shell 命令中)?

bur*_*arr 4 google-colaboratory

我了解有表单,但不知道如何从一个单元格获取表单输入并在其他多个单元格中使用输入。

谢谢你!

我研究过表单,但它们仅适用于非常基本的代码。我正在尝试运行一个 python 程序,这意味着我的单元代码为

!python3 <nameofprogram>.py -flags arguments
Run Code Online (Sandbox Code Playgroud)

这些参数是我想要更改的内容,但是即使使用下拉表单选择,我也无法让代码理解该参数来自表单,而不是采用文字文本,而当我更改落下。

这是单元格的代码:

Section = "tracks" #@param ["tracks", "newalbums", "justreleased", "pop", "rock", "electronic", "country", "hiphop", "rnb", "kpop", "classical", "jazz", "latin", "holiday"]
!python3 redsea.py -a TV explore atmos Section
Run Code Online (Sandbox Code Playgroud)

我看不到对我有帮助的答案。

我找到的最终答案是在代码中的片段之前使用 $ 。

!python3 redsea.py -a TV explore atmos $Section
Run Code Online (Sandbox Code Playgroud)

询问输入后。

Bob*_*ith 8

input您可以使用如下函数提示用户输入:

file_name = input('Enter the file name: ')
print(f'You entered {file_name}')
Run Code Online (Sandbox Code Playgroud)

这是一个完整的示例:

https://colab.research.google.com/drive/1OXsj6GqG76AK7DE-DUPo0zGOiiZjYwX0?​​usp=sharing

在此输入图像描述