loop does not count...
Jonathan Driller
jdriller at orchid.org
Tue Nov 18 12:48:15 EST 2003
More information about the Python-list mailing list
Tue Nov 18 12:48:15 EST 2003
- Previous message (by thread): loop does not count...
- Next message (by thread): Pythom HTML Libraries
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thanks.
That worked beautifully - except that I kept getting errors if I moved
the import statements out of the def... "invalid syntax"
So, now it is (with the changed comments per Terry's suggestion to be
added):
def stats():
import sys
import string
#read the file of current urls that are to be checked - presumes
it exists already
x = open('urlList.txt')
# note this reads as a file, not a list
urlFile = x.read()
# don't need to close but should
x.close()
#list what is in text file of urls
print "Here is what we check now:\n", urlFile
print "\n"
#prompt to add additional urls - use raw so quotes not nec
addItem = raw_input('Enter an additional URL in quotes:' )
# can't append() to a file, must list.append() or do this way
urlList = urlFile + "\n" + addItem
#write additional urls to list
y = open('urlList.txt', 'w')
y.write(urlList)
y.close()
# len(listName) gives # of list elements
#turn url listings into list
z = open('urlList.txt')
urlList = z.readlines()
#open log file
log = open('sampleLog.txt')
logFile = log.read()
#initialize counter at 0
i = 0
# loop through to search for urls
while i < len(urlList):
# put element into var
check = urlList[i].strip()
#print out # found and what it was
print check, " found" , string.count(logFile, check) ,"times
\n"
# increment for next item - can't do i ++
i = i + 1
z.close()
- Previous message (by thread): loop does not count...
- Next message (by thread): Pythom HTML Libraries
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list