python 如何获得重定向输入

2025-12-01 0 52,849

通过内置的fileinput模块即可实现,创建文件filein.py:

#!/usr/bin/env python
import fileinput
f_input = fileinput.input()
for line in f_input:
     print(line, end='')

相关推荐:《Python教程》

增加可执行权限:

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.

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 python基础 python 如何获得重定向输入 https://www.zhiup.top/5554.html

相关