【问题标题】:How to access python variables in Sagemaker Jupyter Notebook shell command如何在 Sagemaker Jupyter Notebook shell 命令中访问 python 变量
【发布时间】:2020-06-23 18:35:08
【问题描述】:

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

region="us-west-2"

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

!echo $region

输出

us-west-2

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

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

$ variable-name 在 jupyter 单元 ! shell command 内没有帮助

【问题讨论】:

    标签: python bash shell jupyter-notebook amazon-sagemaker


    【解决方案1】:

    在这里回答:https://stackoverflow.com/a/19674648/5157515

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

    但是使用魔法命令%%bash 是可能的

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

    【讨论】:

      【解决方案2】:

      您现在可以使用括号来执行此操作:

      region = 'us-east-2'
      !echo {region}
      

      【讨论】:

        猜你喜欢
        • 2019-10-16
        • 2020-01-24
        • 1970-01-01
        • 2018-06-01
        • 1970-01-01
        • 2022-12-28
        • 1970-01-01
        • 2022-07-17
        • 2019-11-24
        相关资源
        最近更新 更多