【问题标题】:python argument using < (io redirection) in linux在linux中使用<(io重定向)的python参数
【发布时间】:2017-03-11 20:15:24
【问题描述】:

在 python 3 中,如何在 Linux 命令提示符下使用 {

例子

{python script.py result.log} 或 {python script.py ~/test/result.log}

【问题讨论】:

  • 你无法说出文件的名称。 shell 不会给你这些信息。
  • 一旦你使用了重定向,你的 python 脚本就不再从文件中读取,而是从标准输入(文件描述符 0)中读取

标签: python shell parameter-passing command-line-arguments


【解决方案1】:
import sys

input_text = sys.stdin.read()

sys.stdin 就像一个文件,所以你也可以使用.readlines() 或者逐行遍历它。

【讨论】:

    猜你喜欢
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2019-06-15
    • 1970-01-01
    • 2012-04-23
    • 2010-11-06
    • 2016-01-09
    相关资源
    最近更新 更多