Changes

Jump to: navigation, search

OPS435 Python Lab 5

248 bytes added, 16:10, 4 September 2017
PART 1 - Reading Data From Files
dir(f)
</source>
:#Lets inspect some of the functions . attributes and methods that we can use on this file object.<source lang="python">help(f.read) # Reads help for reading all lines and stores in a stringhelp(f.readlines) # Reads help for reading all lines and stores in a listhelp(f.readline) # Reads help for reading first line, if run a second time it will read the second line, then thirdhelp(f.writable) # help for writing all lines and stores in a stringhelp(f.close) # help for closing the opened file
f.writable() # Object method (function returns value)
f.name # Object attribute (variable string)
f.closed # Object attribute (variable boolean)
</source>
:#Next , issue the following command to both read data from the file and store that data into the variable called "read_data", and then close the file to free up resources.:<source lang="python">
read_data = f.read()
read_data
13,420
edits

Navigation menu