How to design a class that will listen on stdin?
Dan Sommers
2QdxY4RzWzUUiLuE at potatochowder.com
Sat May 23 12:20:10 EDT 2020
On Saturday, May 23, 2020, at 07:24 -0400, zljubisic at gmail.com wrote:
> I have to talk to outer system by stdin/stdout.
> Each line that comes to stdin should be processed and its result returned back to stdout. Logging should go to stderr.
>
> How to design a class that will listed to stdin and call required methods in order to process the data?
I wouldn't put it into a class, but the core of it looks something like
this:
for line in sys.stdin:
result = process(line)
print(result)
if some_condition():
break
The details may be different, and there's likely more error handling in
production code, but that's the general idea.
More information about the Python-list
mailing list