Changes

Jump to: navigation, search

OPS435 Python Lab 5

36 bytes removed, 11:16, 8 October 2018
PART 1 - Reading Data From Files
read_data = f.read() # Read from file
f.close() # Close file</source>
:#read_data in this case contains the data from the file in a single <u>long</u> string. The end of each line in the file will show the special character ''''\n'''' which represents the '''newline character''' in a file used to separate lines (or records in a traditional "flat database file"). It would be convenient to '''split''' the line on the new-line characters, so each line can be stored into a separate array elements (or as an item in our case, a list!).<br><br>
:#Store the contents of our file into a list called '''list_of_lines''':<source lang="python">
read_data.split('\n') # Returns a list
1,760
edits

Navigation menu