I have a cell with this content:
import os os.mkdir('123') name = '123' !rm -r name
I want to pass the value of the variable name to the last line. How can I do this?
It's already possible to run terminal commands in a Colab notebook — all you need to do is prepend an exclamation to the command, or use the %%shell command, but sometimes you might prefer the convenience an interactive shell.
To create a variable, provide an initial value. The tf. Variable will have the same dtype as the initialization value. A variable looks and acts like a tensor, and, in fact, is a data structure backed by a tf.
To simply have all the cells run automatically, click Runtime > Run all in the colab toolbar.
Try $
. It will substitute the python variable.
!rm -r $name
You may need to use $name\.txt
or {name}.txt
in some cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With