Jquery中文网 www.jquerycn.cn
Jquery中文网 >  Python编程  >  Python入门  >  正文 python 如何获得重定向输入

python 如何获得重定向输入

发布时间:2021-05-20   编辑:www.jquerycn.cn
jquery中文网为您提供python 如何获得重定向输入等资源,欢迎您收藏本站,我们将为您提供最新的python 如何获得重定向输入资源

通过内置的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.

您可能感兴趣的文章:
python 如何获得重定向输入
Python 简介
python为何如此流行
Python的sys有哪些功能
python中sys是什么模块
python如何模拟登录Github
linux如何打开python
linux中如何使用python
python做后端好吗
python难还是ruby难

[关闭]