Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 5

87 bytes added, 17:37, 4 September 2017
PART 1 - Reading Data From Files
:#Issue both method1 and method2 sequence of commands to see how you can store data into a list more efficiently:<source lang="python">
# METHOD 1:
 
f = open('data.txt', 'r')
method1 = list(f)
f.close()
method2
</source>:#Finally<br>Sometimes, sometimes all that needs you may need to be done is to print only display retrieved data on the file screen as opposed to processing the screendata. In these simple cases, there is no need to create extra/-large variables to store the data, instead just but rather print it to the screen one line at a timeonto the screen. Doing one of the following methods Using this method will save computer resources while reading files.<source lang="python"><br><br>:#To demonstrate, issue the following code sequence:<source lang="python"
f = open('data.txt', 'r')
for line in f:
13,420
edits