the INPUT = str ( " Please enter: " ); Print ( " what you type is: " , str)
# Open a file f = Open ( " /tmp/foo.txt " , " w " ) f.write ( " Python is a great language. \ N Yes, it was really good !! \ the n- " ) # close open the file f.close ()
# Open a file F = Open ( " /tmp/foo.txt " , " R & lt " ) STR = reached, f.read () Print (STR) # open files are closed f.close ()
# Open a file F = Open ( " /tmp/foo.txt " , " R & lt " ) STR = f.readline () Print (STR) # open files are closed f.close ()
# Open a file F = Open ( " /tmp/foo.txt " , " R & lt " ) STR = f.readlines () Print (STR) # open files are closed f.close ()
# Open a file F = Open ( " /tmp/foo.txt " , " R & lt " ) for Line in F: Print (Line, End = '' ) # open files are closed f.close ()
# Open a file f = Open ( " /tmp/foo.txt " , " w " ) NUM = f.write ( " Python is a great language. \ N Yes, it was really good !! \ the n- " ) Print (NUM) # close open files f.close ()
# Open a file F = Open ( " /tmp/foo1.txt " , " W " ) value = ( ' www.runoob.com ' , 14 ) S = STR (value) f.write (S) # close the open file f.close ()
Import pickle # using the pickle module to save the data object to a file DATAl = { ' A ' : [. 1, 2.0,. 3,. 4 + 6J ], ' B ' : ( ' String ' , U ' the Unicode String ' ), ' C ' : None} selfref_list = [. 1, 2,. 3 ] selfref_list.append (selfref_list) Output = Open ( ' data.pkl ' , ' WB ' ) # Pickle Protocol of 0. The Dictionary the using the pickle.dump (DATAl,output) # Pickle the list using the highest protocol available. pickle.dump(selfref_list, output, -1) output.close()
Import the pprint, pickle # using the pickle module python reconstructed object from the file pkl_file = Open ( ' data.pkl ' , ' RB ' ) DATAl = the pickle.load (pkl_file) pprint.pprint (DATAl) DATA2 = the pickle.load (pkl_file ) pprint.pprint (data2) pkl_file.close ()