Writing data to a newly-created file

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()

How it works...

The important thing to note at this point is that the newline character is the natural way by which Python separates variables. Space characters will also be used as number or character value separators or delimiters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.50.156