reading and appending to the end of the file. Here is
what the code would look like:
Click here to view code image
with open("textfile.txt", "a+") as data:
data.write('\nFourth line added by Python')
Notice the newline in front of the text you are appending
to the file. It appears here so that it isn’t just tacked on at
the very end of the text. Now you can read the file and
see what you added:
Click here to view code image
with open ("textfile.txt", "r") as data:
print(data.read())
Line one of a text file
Line two of a text file, just like line one, but
the second one.
Third line of a text file.
Fourth line added by Python
PARSING DATA
Imagine a world where all the data is in nice, neatly
formatted cells, completely structured, and always
consistent. Unfortunately, data is not so easily accessible,
as there are a multitude of types, structures, and formats.
This is why it is essential that you learn how to parse
data in some of the more common forms within your
Python programs.
Comma-Separated Values (CSV)
A CSV file is just a plaintext spreadsheet or database file.
All of those spreadsheets or databases that you have with
infrastructure information can be easily exported as CSV
files so that you can use them as source data in Python.