pickle module doesn't work for this simple code
Question: when i run this code in Python 3.4.2(win7-64) it doesn't work! it creates file
but nothing in it.(0 bytes) I don't know what is the problem? Help- Thanks
Windo

    
    
    import  pickle
    f=open ("G:\\database.txt","wb")
    pickle.dump (12345,f)
    


Answer: You have to close the file object that you have opened. So just add the line

    
    
    f.close()
    

at the end and it will work.

As an alternative, you can also use the `with` statement to open the file,
then it will automatically close the file for you when it's done:

    
    
    import pickle
    with open("G:\\database.txt", "wb") as f:
        pickle.dump( 12345,  f )
    

