【发布时间】:2021-03-11 20:49:29
【问题描述】:
我有一个 python 程序,它从标准输入读取输入(必需),并从标准输入处理行:
for lines in stdin:
#do stuff to lines
filename = #need file name
#example print
print(filename)
但是,在这个 for 循环中,我还需要像这样获取已通过管道传输到这个 python 程序的文件的名称:
cat document.txt | pythonFile.py #should print document.txt with the example print
有没有办法做到这一点?
【问题讨论】:
-
当您可以将文档文件作为参数传递给脚本时,您能否提供更多信息,说明为什么要将文件名通过管道传递给 python 脚本?
-
@RushikeshGaidhani 这是学校作业的一部分。说明告诉我们必须从标准输入获取输入。