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

 

 

 

 

 

 

 

    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM