[Tutor] converting xls to csv

Nick Burgess burgess.nick at gmail.com
Sun May 31 11:09:11 CEST 2009


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.gauld at btinternet.com> wrote:
>
> "Nick Burgess" <burgess.nick at 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  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list