当前位置: 动力学知识库 > 问答 > 编程问答 >

shell - python argument using < (io redirection) in linux

问题描述:

In python 3 how to read an entire file using {<} from Linux command prompt. How to access and figure out the input is {textfile.txt} or {extract.txt} inside python code.

example

{python script.py < textfile.txt > result.log} or {python script.py < ../directory2/extract.txt > ~/test/result.log}

网友答案:
import sys

input_text = sys.stdin.read()

sys.stdin is like a file, so you can also use .readlines() or iterate over it line by line.

分享给朋友:
您可能感兴趣的文章:
随机阅读: