现在的位置: 首页 > 综合 > 正文

关于ipython与shell结合的问题

2018年04月02日 ⁄ 综合 ⁄ 共 558字 ⁄ 字号 评论关闭

这是《Python+UNIX和Linux系统管理指南》上的一个例子,发现有点出入,for 循环中shell引用python变量不需要加入$符号,可能与ipython版本有关,我的是ipython 0.12版本

In [46]: cd test
/root/test/test

In [47]: for  i  in range(10):
   ....:     !date > {i}.txt
   ....:     

In [48]: ll
total 40
-rw-r--r-- 1 root 29 Aug 27 12:37 0.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 1.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 2.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 3.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 4.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 5.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 6.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 7.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 8.txt
-rw-r--r-- 1 root 29 Aug 27 12:37 9.txt

In [49]: !cat 9.txt
Mon Aug 27 12:37:31 CST 2012

In [50]: 

抱歉!评论已关闭.