Writing data to multiple files

We see here that opening and writing data to a series of separate files is, as we have come to expect from Python, very simple and straightforward. Once we have seen an example of the correct syntax, it just works.

# file_write_2.py
#>>>>>>>>>>>>>
# Let's create a file and write it to disk.
filename_1 = "/constr/test_write_1.dat"
filly = open(filename_1,"w") # Create a file object, in # write mode
filly.write("This is number one and the fun has just begun")
filename_2 = "/constr/test_write_2.dat"
filly = open(filename_2,"w") # Create a file object, in # write mode
filly.write("This is number two and he has lost his shoe")
filename_3 = "/constr/test_write_3.dat"
filly = open(filename_3,"w") # Create a file object, in # write mode
filly.write("This is number three and a bump is on his knee")
#filly.close()

How it works...

The value of this example is that it provides examples of correct debugged syntax. So it is available for reuse and modification with the minimum of bother.

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

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