Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 5

330 bytes added, 15:22, 4 September 2017
PART 1 - Reading Data From Files
f.closed # Object attribute (variable boolean)
</source>
:#Next , issue the following commands to read data from the file and close store that data into the variable called "read_data", and confirm the contents of the file to free up resources.variable "read_data:<source lang="python">
read_data = f.read()
read_data
</source>
:#Finally Prior to closing the file, you should close the file in order to free up the computer resources. First lets check to see if the file is already closed.Issue the following object attribute will provide a boolean value if the file is closed (true) or open (false):<source lang="python">f.closed </source>:# This Finally, issue the following object method and object attribute will give true if to first close the file, and then verify that the file is has been successfully closed and false if open:<source lang="python">
f.close() # This method will close the file
f.closed # Confirm the file is closed
13,420
edits