从linux命令行读取Python [英] Reading from linux command line with Python
本文介绍了从linux命令行读取Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法读取进入命令行的数据,直接进入另一个Python脚本执行?
Is there a way to read data that is coming into the command-line, straight into another Python script for execution?
推荐答案
您需要从python脚本中阅读 stdin
。
You need to read stdin
from the python script.
import sys
data = sys.stdin.read()
print 'Data from stdin -', data
运行示例 -
$ date | python test.py
Data from stdin - Wed Jun 17 11:59:43 PDT 2015
这篇关于从linux命令行读取Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文