How can I accept an input in google colab then use that input throughout the code?

Viewed 7477

I understand there are forms, but not how to take a form input from one cell and use the input in other multiple cells.

Thank you!

I've looked into forms, but they only work for very basic code. I am trying to run a python program which means I have the cell code as !python3 .py -flags arguments

The arguments are what I'd like to change, however even with a dropdown form selection, I can't get the code to understand that the argument is from a form, instead of taking the literal text which doesn't when I change the dropdown.

Here's the cell's code:

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

I see no answers that help me.

The final answer I found was to use $ before the piece in the code.

!python3 redsea.py -a TV explore atmos $Section

After asking for the input.

2 Answers

You can just use input().

name = input("Your name: ")

Then in another cell, you can use the name variable.

Here's a notebook to test.

Related