Created
July 21, 2022 16:03
-
-
Save opplatek/016a4631d834453e28d3a28e6d94f66b to your computer and use it in GitHub Desktop.
Regular input or stdin/stdout decision for Python3 script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
# If intab (input) is defined, read it; if not assume stdin | |
if intab: | |
f = open(intab, "r") | |
else: | |
f = sys.stdin | |
# If otab (output) is defined, read it; if not assume stdout | |
if otab: | |
fout = open(otab, "w") | |
else: | |
fout = sys.stdout | |
# Do whatever you want | |
for line in f: | |
print(line) | |
write.fout(line) | |
# And close files, just to be safe | |
if f is not sys.stdin: | |
f.close() | |
if fout is not sys.stdout: | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment