Python中文
首页
教程
问答
标签
搜索
登录
注册
Jupyter/IPython SList::从shell执行操作符“”获取未经标记的输出
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>在<code>Jupyter Notebook Python Cell</code>中运行shell命令时,如下所示:</p> <p><code>output = ! some-shell-command</code></p> <p>发射到标准输出(<code>stdout</code>)的每一行都被捕获到一个类似于</em><code>IPython</code>的<code>SList</code>数据结构中。例如:</p> <pre><code>output = !echo -e 'line1\nline2\nline3' print(output) # A IPython SList data-structure. </code></pre> <p><code>['line1', 'line2', 'line3']</code></p> <p>但是,有时您希望保留原始字符串输出格式,而不将其标记到列表中,如下所示:</p> <p><code>print(output)</code></p> <pre><code>line1 line2 line3 </code></pre> <p><em>示例:对于结构化JSON输出(一个包含许多换行符的字符串),您不希望出现这种标记化</em></p> <p>那么,如何使用<code>!</code>操作符在<code>Jupyter Notebooks</code>中执行shell命令,并检索未标记化的输出(如上所述)</p> <p>理想情况下,解决方案应该是<code>Jupyter Notebooks</code>中的本地解决方案</p> <p>谢谢大家!</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>使用<code>join()</code>将迭代器组合成字符串</p> <pre><code>"\n".join(output) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
pyVISA GPIB GET(组执行触发器)
8 回答
Pyvisa IOerror设备:Korad K3005d电源
3 回答
PyVISA mac OS X(山狮)安捷伦33250
7 回答
Pyvisa Pyusb无法加载大于1 MB的序列
2 回答
pyVisa RS232太慢
3 回答
PyVISA RS232超时错误(安捷伦电源)
10 回答
PyVISA SCPI命令和查询(值更新问题)
1 回答
PyVISA SerialInstrument需要硬重置才能在故障后连接
2 回答
pyvisa,未找到函数viOpen
5 回答
pyVISA:以编程方式将仪器返回到本地模式
9 回答
pyvisa:接口类型是什么意思?
6 回答
pyvisa.errors.VisaIOError:VI_ERROR_TMO(1073807339):操作完成前超时
6 回答
PyVisa“更复杂的示例”根本不运行Keithley 2400不理解的命令
9 回答
PyVisapy后端
4 回答
PyVISA不能写入超过7F的十六进制字符
9 回答
PYVISA中的ENUM模块和cStringIO模块
2 回答
PyVisa代码的图形用户界面
2 回答
Pyvisa使用按键电源超时
7 回答
PyVISA和Kethley 2701只能从一个通道获取结果
9 回答
PyVisa和Printing New D
6 回答