How to use Python variables in Google Colab terminal command?

≡放荡痞女 提交于 2020-04-12 14:05:55

问题


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?


回答1:


Try $. It will substitute the python variable.

!rm -r $name

You may need to use $name\.txt or {name}.txt in some cases.



来源:https://stackoverflow.com/questions/52851718/how-to-use-python-variables-in-google-colab-terminal-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!