Am basically using the same code - the first which uses a function
getAnchors() fails to find a match, the second which I added to help debug
works fine. I just cannot see why one works and the other does not....
Could someone please put me out of my misery!!
Using 2.6
########
#!/usr/bin env python
import os
import fnmatch
import re
basedir="/home/mark/www/dev/ready"
srchdirs=['/', '/static', '/static/lpi101', '/static/lpi102',
'/static/lpi201', '/static/lpi202',
'/static/misc','/static/images','/static/css','/static/code','/static/about']
anchor=re.compile(r'id=":[a-zA-Z].*:[0-9]{3}-[0-9]{1,2}-[0-9]{1,2}')
anhref=re.compile(r'href="/.*\.(html|css|js).*?"')
anchors=[]
hrefs=[]
def readFile(file):
try:
fp=open(file, 'r')
allLines=fp.readlines()
fp.close
return allLines
except IOError, e:
msg='Error %d: %s' % (e.args[0], e.args[1])
return str(msg)
# Anchors will only exist in .html files
def getAnchors():
for eachdir in srchdirs:
aDir=basedir+eachdir
for aFile in os.listdir(aDir):
if fnmatch.fnmatch(aFile, '*.html'):
contents=readFile(aFile)
if type(contents) == '': print contents
else:
for line in contents:
res=anchor.search(line)
### Fails to find a match - though does do in the code below
if res != None:
anchors.append(res.group()[4:])
getAnchors()
## Below works - finds a match(s)
contents=readFile('/home/mark/www/dev/ready/static/lpi101/lpi101-chapt-1-3.html')
for line in contents:
res=anchor.search(line)
if res != None:
anchors.append(res.group()[4:])
--
View this message in context:
http://old.nabble.com/help-please---cannot-figure-this-out%21-tp27026738p27026738.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss