Is there a way to read from stdin in Python?

Asked 1 years ago, Updated 1 years ago, 55 views

I need to get input only from stdin, how do I do it on Python?

python stdin

2022-09-21 20:35

1 Answers

sysUse the module

import sys
for line in sys.stdin:
    print line

If you want to get the file name as command line argument and read the file, We recommend the fileinput module. If you're given a file name, read it to me If you're not given anything, read it on stdin.

import fileinput
for line in fileinput.input():
    pass


2022-09-21 20:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.