-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsample3.py
More file actions
20 lines (15 loc) · 703 Bytes
/
sample3.py
File metadata and controls
20 lines (15 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
myfile = open("pennregistrar/afrc.html")
count = 0
for line in myfile:
# the find() method searches a string for the occurence of another string.
# if it finds it, it returns the index where it occurs. if it's not found it returns -1
if (line.find("CU") != -1):
print line
# this increments the value of count by 1
count += 1
# cleaning up by closing the file we opened
myfile.close()
# before we looked at how to print some basic text
# this is how you print something to screen that has variables and plain text mixed
# the %(count)d part will be filled in by the value of an integer passed in at the end
print "counted %(count)d classes" % { "count": count }