Add first file I/O example for scooper
parent
30b919d602
commit
f7e3296b6c
@ -0,0 +1,4 @@
|
||||
# File I/O Examples
|
||||
|
||||
This directory will contain some examples of using Python for file I/O as
|
||||
Spencer requested.
|
@ -0,0 +1,12 @@
|
||||
Spencer
|
||||
Freena
|
||||
Aaron
|
||||
Toby
|
||||
Thomas
|
||||
Mulbah
|
||||
Jeff
|
||||
Shallon
|
||||
Janet
|
||||
Daniel
|
||||
Jallah
|
||||
Annie
|
@ -0,0 +1,13 @@
|
||||
# Load the people from the data file for reading
|
||||
f = open('people.dat', 'r')
|
||||
# read in names, one per line
|
||||
names = f.readlines()
|
||||
# we're done with the file, close it
|
||||
f.close()
|
||||
# each name still has a newline, '\n' on the end of it, let's remove that
|
||||
cleaned_names = []
|
||||
for name in names:
|
||||
cleaned_names.append(name[:-1])
|
||||
# now let's print out the names in alphabetical order
|
||||
for name in sorted(cleaned_names):
|
||||
print(name)
|
Loading…
Reference in New Issue