首页 > 解决方案 > python标准输入输出

问题描述

该函数在 tempconv.py 文件中定义为

def fahr2cels(fahr) :
    cels = 5/9 * (fahr - 32)
    return cels 

并且有一个名为 tempmax_cels.txt 的文本文件,它是一行数字。我想在 bash shell 中写一个命令行

python tempconv.py < tempmax_cels.txt 

因此计算机可以接受文本文件作为标准输入。我该如何纠正 tempconv.py 来做到这一点?(使用导入系统模块)

标签: pythoninputstandards

解决方案


这个答案提供了您问题的所有细节,比我能做的更好: https ://stackoverflow.com/a/38670261/12602635


推荐阅读