导语:
本文主要介绍了关于python 如何获得重定向输入的相关知识,包括python爬虫用什么,以及python 跳转到指定代码行这些编程知识,希望对大家有参考作用。
通过内置的fileinput模块即可实现,创建文件filein.py:
#!/usr/bin/env python
import fileinput
f_input = fileinput.input()
for line in f_input:
print(line, end='')
增加可执行权限:
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中time.localtime的使用12/16
- ♥ python单继承和多继承怎么定义?12/10
- ♥ python如何连接两个列表09/21
- ♥ 如何输入python函数参数10/16
- ♥ 如何判断python是否已经安装11/02
- ♥ 如何在python2.7 64位中下载setuptools?11/27
内容反馈