Is there a way to read from stdin in Python?

Asked 2 years ago, Updated 2 years ago, 61 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.