新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
python中獲得重定向輸入的方法-創(chuàng)新互聯(lián)
創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務器提供商,新人活動買多久送多久,劃算不套路!
這篇文章主要介紹python中獲得重定向輸入的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
通過內置的fileinput模塊即可實現(xiàn),創(chuàng)建文件filein.py:
#!/usr/bin/env python import fileinput f_input = fileinput.input() for line in f_input: print(line, end='')
增加可執(zhí)行權限:
chmod a+x filein.py
使用:
$ ls | ./filein.py # Prints a directory listing to stdout. $ ./filein.py /etc/passwd # Reads /etc/passwd to stdout. $ ./filein.py < /etc/passwd # Reads /etc/passwd to stdout.
以上是python中獲得重定向輸入的方法的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)-成都網站建設公司行業(yè)資訊頻道!
網站名稱:python中獲得重定向輸入的方法-創(chuàng)新互聯(lián)
當前URL:http://www.ef60e0e.cn/article/dgsesd.html