We now create a file and then write a small amount of data to it. The value of these very, very simple recipes is that when we are trying some task that is complex and things do not work as expected, the simple one-action-only test programs allow us to break our problem down into simple tasks that we can gradually add complexity to, verifying the validity of each new change. This is a tried and trusted philosophy used by many of the best programmers.
# file_write_1.py #>>>>>>>>>>>>> # Let's create a file and write it to disk. filename = "/constr/test_write_1.dat" filly = open(filename,"w") # Create a file object, in write # mode for i in range(0,2): filly.write("everything inside quotes is a string, even 3.1457") filly.writelines(" ") filly.write("How will stored data be delimited so we can read chunks of it into elements of list, tuple or dictionart?") filly.writelines(" ") #filly.close()
13.58.50.156