Python shlex 模块

shlex 模块最常用的是 split() 函数,用来分割字符串,通常与 subprocess 结合使用

In [1]: import shlex

In [2]: shlex.split('my name is tom')
Out[2]: ['my', 'name', 'is', 'tom']
In [1]: import shlex, subprocess

In [2]: subprocess.Popen(shlex.split('ls -l /data'))
总用量 0
-rw-r--r--. 1 root root 0 1月  22 12:09 1.txt
-rw-r--r--. 1 root root 0 1月  22 12:09 2.txt
-rw-r--r--. 1 root root 0 1月  22 12:09 3.txt

 

 

 

 

 

 

 

    

posted @ 2019-01-22 12:22  孔雀东南飞  阅读(6831)  评论(0编辑  收藏  举报