How do you read from stdin in Python? - Stack Overflow

How do you read from stdin in Python? - Stack Overflow

瀏覽:470
日期:2025-09-12
Building on all the anwers using sys.stdin, you can also do something like the following to read from an argument file if at least one argument exists, and fall back to stdin otherwise: import sys f = sys.stdin if len(sys.argv) > 1: f = open(sys.argv[1]) ...看更多