Got it. the row is not a string or buffer but the cell is..
for row in spamReader: for cell in row: if pattern.search(cell): print ', '.join(row) On Sun, May 31, 2009 at 5:09 AM, Nick Burgess <burgess.n...@gmail.com> wrote: > Thank you for your response and my apologies for the non-useful > output. After searching again this task has been done by > pyExcelerator, the tool xls2csv-gerry.py does this great. I am now > trying to parse through the csv's and return the rows containing the > matching strings. Python is looking for string or buffer, this method > worked from a text search script, I am stumped on this for now. > > > import re > import csv > > pattern = re.compile(r'10\.229\.127\.255') > spamReader = csv.reader(open('MasterIPList.csv'), delimiter=' ', > quotechar='|') > for row in spamReader: > if pattern.search(row): > print ', '.join(row) > > > error > > F:\python>MastIPparse.py > Traceback (most recent call last): > File "F:\python\MastIPparse.py", line 9, in <module> > if pattern.search(row): > TypeError: expected string or buffer > > > When I comment out line 9 it returns all of the rows, so I now its reading > OK.. > > Thanks for your time, > > -nick > > On Sun, May 31, 2009 at 3:57 AM, Alan Gauld <alan.ga...@btinternet.com> wrote: >> >> "Nick Burgess" <burgess.n...@gmail.com> wrote >>> >>> I am trying to make this code work. I don't have any experience with >>> defining things and this is my second program. The error returmed is >>> "SyntaxError: invalid syntax" >> >> Please post the whole error message, much of the useful stufff - like the >> location of the problem! - is in the earlier lines. >> >> However taking a wild guess - are you using Python v3? >> >>> print "------ beginning to convert XLS to CSV ------" >> >> If so print is now a function so you need to surround the string with () >> >> But if you are not using v3, then please send the fuill error text. >> >> >> -- >> Alan Gauld >> Author of the Learn to Program web site >> http://www.alan-g.me.uk/ >> >> _______________________________________________ >> Tutor maillist - tu...@python.org >> http://mail.python.org/mailman/listinfo/tutor >> > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor