Thanks everyone, the following code works great.  It returns the name
of the file and the row that matched the reqex.  Is it posible to take
the regex compile from user input?  To make it take an argument,  like

> csvSearch.py 10.192.55

af = re.compile(sys.argv[1])
pattern = re.compile(af)          ....?



pattern = re.compile(r'10\.191\.2')
files = glob.glob("*.csv")

for f in files:
    ff = csv.reader(open (f, 'rb'), delimiter=' ', quotechar='|')
    for row in f:
        for row in ff:
            for cell in row:
                if pattern.search(cell):
                    print f
                    print ', '.join(row)

On Sat, Jun 6, 2009 at 4:39 PM, Sander Sweers<[email protected]> wrote:
> 2009/6/6 Emile van Sebille <[email protected]>:
>>> for f in files:
>>>    print f
>>>    csv.reader(open (f), delimiter=' ', quotechar='|')
>>
>> you open it here, but don't save a reference to the opened file.  Try...
>>      ff = csv.reader(open (f), delimiter=' ', quotechar='|')
>
> <snip>
>
>>    reader(...)
>>        csv_reader = reader(iterable [, dialect='excel']
>>                                [optional keyword args])
>>            for row in csv_reader:
>>                process(row)
>
> If you are on windows you should open the file in binary mode.
>  open(f, 'rb')
>
> Greets
> Sander
> _______________________________________________
> Tutor maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to