Pipe Ipython magic output to a variable?

后端 未结 3 850
面向向阳花
面向向阳花 2020-12-09 15:26

I want to run a bash script in my ipython Notebook and save the output as a string in a python variable for further manipulation. Basically I want to pipe the output of the

3条回答
  •  孤街浪徒
    2020-12-09 16:09

    Notice the difference in the variable type between @MattDMo (SList) and @oLas (str) answers:

    In [1]: output = !whoami
    
    In [2]: type(output)
    Out[2]: IPython.utils.text.SList
    
    In [3]: %%bash --out output
       ...: whoami
    
    In [4]: type(output)
    Out[4]: str
    

提交回复
热议问题