Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Alan Gauld
"Nick Burgess" wrote for root, dirs, files in os.walk('./'): for f in files: if f.endswith('.txt'): allfiles.append(os.path.join(root, f)) myFunction( os.path.join(root,f) ) This returns a list of the *.txt files. Of course now I am stuck on how to appl

Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Nick Burgess
forgot to add this at the top, allfiles = [] On Tue, May 5, 2009 at 6:15 PM, Nick Burgess wrote: > for root, dirs, files in os.walk('./'): >    for f in files: >        if f.endswith('.txt'): >            allfiles.append(os.path.join(root, f)) > > This returns a list of the *.txt files. Of cours

Re: [Tutor] returning the entire line when regex matches

2009-05-05 Thread Nick Burgess
for root, dirs, files in os.walk('./'): for f in files: if f.endswith('.txt'): allfiles.append(os.path.join(root, f)) This returns a list of the *.txt files. Of course now I am stuck on how to apply the delimiter and search function to the items in the list..? Any clues/ex

Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Alan Gauld
Mr. Gauld is referring to!! I searched python.org and alan-g.me.uk. Does anyone have a link? I posted a link to the Python howto and my tutorial is at alan-g.me.uk You will find it on the contents frame under Regular Expressions... Its in the Advanced Topics section. -- Alan Gauld Author of t

Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Nick Burgess
Compiling the regular expression works great, I cant find the tutorial Mr. Gauld is referring to!! I searched python.org and alan-g.me.uk. Does anyone have a link? On Mon, May 4, 2009 at 1:46 PM, Martin Walsh wrote: > Nick Burgess wrote: >> So far the script works fine, it avoids printing the

Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Martin Walsh
Nick Burgess wrote: > So far the script works fine, it avoids printing the lines i want and > I can add new domain names as needed. It looks like this: > > #!/usr/bin/python > import re > > outFile = open('outFile.dat', 'w') > log = file("log.dat", 'r').read().split('Source') # Set the line delim

Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Alan Gauld
"Nick Burgess" wrote for line in log: if not re.search(r'notneeded.com|notneeded1.com',line): outFile.write(line) I tried the in method but it missed any other strings I put in, like the pipe has no effect. More complex strings will likely be needed so perhaps re might be better..?

Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Nick Burgess
So far the script works fine, it avoids printing the lines i want and I can add new domain names as needed. It looks like this: #!/usr/bin/python import re outFile = open('outFile.dat', 'w') log = file("log.dat", 'r').read().split('Source') # Set the line delimiter for line in log: if not re.

Re: [Tutor] returning the entire line when regex matches

2009-05-03 Thread Alan Gauld
"Alan Gauld" wrote How do I make this code print lines NOT containing the string 'Domains'? Don't use regex, use in: for line in log: if "Domains" in line: print line Should, of course, be if "Domains" not in line: print line Alan G. _

Re: [Tutor] returning the entire line when regex matches

2009-05-03 Thread Alan Gauld
"Steve Willoughby" wrote if re.search != (r'Domains:', line): Because you are assigning a tuple containing a string and a line of text to a name which is currently bound to a function object (re.search) Actually, he's COMPARING the two, not assigning. But comparing a function object and a

Re: [Tutor] returning the entire line when regex matches

2009-05-03 Thread Steve Willoughby
Alan Gauld wrote: >> if re.search != (r'Domains:', line): > > Because you are assigning a tuple containing a string and a line of text > to a name which is currently bound to a function object (re.search) Actually, he's COMPARING the two, not assigning. But comparing a function object and a tupl

Re: [Tutor] returning the entire line when regex matches

2009-05-03 Thread Alan Gauld
"Nick Burgess" wrote How do I make this code print lines NOT containing the string 'Domains'? Don't use regex, use in: for line in log: if "Domains" in line: print line This does not work... if re.search != (r'Domains:', line): Because you are assigning a tuple containing

Re: [Tutor] returning the entire line when regex matches

2009-05-03 Thread Steve Willoughby
Nick Burgess wrote: > How do I make this code print lines NOT containing the string 'Domains'? > > > import re > for line in log: > if re.search (r'Domains:', line): > print line > > > This does not work... > > if re.search != (r'Domains:', line): re.search (r'Domains:', line) is

[Tutor] returning the entire line when regex matches

2009-05-03 Thread Nick Burgess
How do I make this code print lines NOT containing the string 'Domains'? import re for line in log: if re.search (r'Domains:', line): print line This does not work... if re.search != (r'Domains:', line): ___ Tutor maillist - Tutor@pytho