如何在Sagemaker Jupyter Notebook Shell命令中访问python变量 [英] How to access python variables in Sagemaker Jupyter Notebook shell command

查看:119
本文介绍了如何在Sagemaker Jupyter Notebook Shell命令中访问python变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Sagemaker笔记本的一个单元格中,我设置了一个变量

In one of the cells of Sagemaker notebook, I've set a variable

region="us-west-2"

在随后的单元格中,我运行以下2个shell命令

In subsequent cell, I run following 2 shell commands

!echo $region

输出

us-west-2

但是,无法使用此变量运行aws shell命令

However, unable to run aws shell command using this variable

!aws ecr get-login-password --region $region

$ variable-name在jupyter单元! shell command

$ variable-name doesn't help inside jupyter cell ! shell command

推荐答案

如此处回答: https://stackoverflow.com/a /19674648/5157515

没有直接方法使用!命令访问python变量.

There's no direct way to access python variables with ! command.

但是通过魔术命令%%bash可以实现

But with magic command %%bash it is possible

%%bash  -s "$region"
aws ecr get-login-password --region $1

这篇关于如何在Sagemaker Jupyter Notebook Shell命令中访问python变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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