Python File handling: standard input and output
Question: 
    import sys 
    
    fileobject=open('file.txt','w')   
    fileobject.write(sys.stdin.readline())
    Cat
    

In the above code, shouldn't cat be in file after execution? However, when I
run it, I find file empty. If my code is wrong, can someone explain how
`sys.stdin.read()` and `sys.stdout.write()` work and their uses?


Answer: You need to close the file

    
    
    import sys 
    
    fileobject = open('file.txt', 'w')   
    fileobject.write(sys.stdin.readline())
    Cat
    fileobject.close()
    

If you want to see the updated file content before closing the file or exiting
the program you can use flush():

    
    
    fileobject.flush()
    

Check this [StackOverflow
Question](http://stackoverflow.com/questions/14555402/understanding-stdin-
stdout-stderr%20question) for standard input/output

