Changes

Jump to: navigation, search

OPS435 Python Lab 5

5 bytes added, 11:09, 8 October 2018
PART 1 - Reading Data From Files
f = open('data.txt', 'r')
</source><br>The '''open()''' function takes two string arguments: a path to a file, and a mode option (to ask for reading, writing, appending, etc). The ''open()'' function will return a file object to us, this file object will allow us to read the lines inside the file.<br><br>
:#Here are the most useful functions for text file manipulation:<source lang="python">
f.read() # read all lines and stores in a string
f.readlines() # read all lines and stores in a list
1,760
edits

Navigation menu