Transcript Arrays
Learning Objectives
1.
2.
Understand how computer programs can
interact with a computer file system.
Know how to read/write data from/to a
simple text file using Python.
Python includes a set of
13 File functions.
File Object
We will look at just two!
File.close()
File.flush()
File.fileno()
File.isatty()
File.next()
File.read([size])
File.readLine([size])
File.readLines([sizehint])
File.seek([offset])
File.tell()
File.truncate([size])
File.write(str)
File.writelines(sequence)
How do we test that this has worked?
In this example, the fo.read function is used
to get the first three lines from a text file.
In this example, the fo.write function is used to
add three lines to a text file.
If the file “test.txt” does not already exist, it will
be created automagically.
Copy this program, to create a simple text file
of names (use any names you like)
Check that your text file has been created
Read the data from the text file you created
in the Bronze Challenge & display on screen.
Use a FOR LOOP to read the data from your
text file of names more efficiently.
Create a program to pick a random name
from a text file of names!