Python File handling: standard input and output -
import sys fileobject=open('file.txt','w') fileobject.write(sys.stdin.readline()) cat
in above code, shouldn't cat in file after execution? however, when run it, find file empty. if code wrong, can explain how sys.stdin.read()
, sys.stdout.write()
work , uses?
you need close file
import sys fileobject = open('file.txt', 'w') fileobject.write(sys.stdin.readline()) cat fileobject.close()
if want see updated file content before closing file or exiting program can use flush():
fileobject.flush()
check stackoverflow question standard input/output
Comments
Post a Comment