Modes for reading files
'r' : use for reading
Remember: all data read from a file is read as a string data type, even if you are reading numbers (integers & floats) 44 would be read as "44"
readline (reads one line at a time as a string value)
# Example code (reading a file)
print("---- read one line at a time ----")
daysFile = open("days.txt",'r')
dataReadline1 = daysFile.readline() # read line 1
dataReadline2 = daysFile.readline() # read line 2
daysFile.close()
print(dataReadline1)
print(dataReadline2)
# NOTE:
#ย
# This command will only read one line into a given variable at a time.
# The computer remembers which line it has read and the next readline will read the next
# until no more lines are available. When the file is closes the computer will start reading
# data from the top of the file again.ย
#
# dataReadline = "Monday\n"
#
# The string data will still have \n present. notice that on the print out a extra lineย
# has been inserted between printouts due to this \n character.