Changes

Jump to: navigation, search

OPS435 Python Lab 5

2 bytes added, 10:49, 8 October 2018
INVESTIGATION 1: Working with Files
:#Now lets write some python code to open this created file for reading. We will define and object called '''"f"''' in order to help retrieve content from our text file. Issue the following:<source lang="python">
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 special 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 file manipulation:<source lang="python">
f.read() # read all lines and stores in a string
1,760
edits

Navigation menu