How to access python variables in Sagemaker Jupyter Notebook shell command

非 Y 不嫁゛ 提交于 2021-01-28 13:31:33

问题


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

region="us-west-2"

In subsequent cell, I run following 2 shell commands

!echo $region

Output

us-west-2

However, unable to run aws shell command using this variable

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

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


回答1:


As answered here: https://stackoverflow.com/a/19674648/5157515

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

But with magic command %%bash it is possible

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


来源:https://stackoverflow.com/questions/62541587/how-to-access-python-variables-in-sagemaker-jupyter-notebook-shell-command

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