A
A
Albert2018-10-17 14:55:03
Python
Albert, 2018-10-17 14:55:03

Google Colab: how to send python variable value to terminal command?

Google Colab can run ipynb files.
There is a cell (cell) with a code.

import os
os.mkdir('123')
name = '123'
!rm -r name

How can I change the last line so that the code works (folder '123' is deleted) without changing the beginning of the line (!rm -r)?
It is the removal through rm that is of interest, and not by means of python (for example, shutil.rmtree () and so on).
Or rather, I’m even interested in the possibility of transferring the values ​​of variables from the python code to the terminal line (in this case, line 4.)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2018-10-17
@bigburn

https://ipython.readthedocs.io/en/stable/interacti...
says it works like this:
!rm -r $name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question