如何在Google Colab终端命令中使用Python变量? [英] How to use Python variables in Google Colab terminal command?

查看:269
本文介绍了如何在Google Colab终端命令中使用Python变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下内容的单元格:

I have a cell with this content:

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

我想将变量 name 的值传递到最后一行. 我该怎么办?

I want to pass the value of the variable name to the last line. How can I do this?

推荐答案

尝试$.它将替换python变量.

Try $. It will substitute the python variable.

!rm -r $name

在某些情况下,您可能需要使用$name\.txt{name}.txt.

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

这篇关于如何在Google Colab终端命令中使用Python变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆