python3:从stdin读取并在EOF上退出

问题描述 投票:0回答:1

我正在从stdin中读取,并处理每一行。简化的代码段:

#!/usr/bin/python3

import os, sys, stat

logfile = '/var/log/mylog'

while True:
    with open(logfile, 'a', buffering=1) as f:

        f_ino = os.stat(logfile)[stat.ST_INO]

        for line in sys.stdin:

            try:
                if os.stat(logfile)[stat.ST_INO] != f_ino:
                    break
            except IOError:
                pass

            f.write(line)

收到EOF后如何退出脚本?

python-3.x eof
1个回答
0
投票

从字面上什么都不做,您的脚本已经在EOF上退出。

© www.soinside.com 2019 - 2024. All rights reserved.