Can I access python variables within a `%

前端 未结 5 790
青春惊慌失措
青春惊慌失措 2020-12-12 17:55

Is there a way to access variables in the current python kernel from within a %%bash or other %%script cell?

Perhaps as command line argume

5条回答
  •  独厮守ぢ
    2020-12-12 18:38

    To include python variables within bash commands run using the syntax ! you can use {} as follows:

    In [1]: for i in range(3):
       ...:     !echo {i+1}
       ...:     
    1
    2
    3
    

    While this is slightly different from what the OP asked, it is closely related and useful in performing a scripting task. This post has more great tips and examples of using shell command within IPython and Jupyter notebooks.

提交回复
热议问题