Re: [Tutor] converting xls to csv

2009-06-07 Thread Sander Sweers
On Sun, 2009-06-07 at 00:54 +0200, Sander Sweers wrote: > 2009/6/6 Nick Burgess : > > Is it posible to take > > the regex compile from user input? To make it take an argument, like > > > >> csvSearch.py 10.192.55 > > You can use raw_input() see [1] for the docs > user_input = raw_input('Please

Re: [Tutor] converting xls to csv

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 5:37 PM, Nick Burgess wrote: > 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 >

Re: [Tutor] converting xls to csv

2009-06-06 Thread Sander Sweers
2009/6/6 Nick Burgess : > Is it posible to take > the regex compile from user input?  To make it take an argument,  like > >> csvSearch.py 10.192.55 You can use raw_inpout() see [1] for the docs user_input = raw_input('Please provide input') Greets Sander [1] http://docs.python.org/library/fun

Re: [Tutor] converting xls to csv

2009-06-06 Thread Nick Burgess
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)

Re: [Tutor] converting xls to csv

2009-06-06 Thread Sander Sweers
2009/6/6 Emile van Sebille : >> 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='|') >    reader(...) >        csv_reader

Re: [Tutor] converting xls to csv

2009-06-06 Thread Emile van Sebille
On 6/6/2009 1:07 PM Nick Burgess said... f seems to be a string containing the file names, so csv.reader isnt actually opening them.. maybe i will play with os.walk..? files = glob.glob("*.csv") Almost there... for f in files: print f csv.reader(open (f), delimiter=' ', quotechar='

Re: [Tutor] converting xls to csv

2009-06-06 Thread Nick Burgess
f seems to be a string containing the file names, so csv.reader isnt actually opening them.. maybe i will play with os.walk..? files = glob.glob("*.csv") for f in files: print f csv.reader(open (f), delimiter=' ', quotechar='|') for row in f: for cell in row: if p

Re: [Tutor] converting xls to csv

2009-06-06 Thread Emile van Sebille
On 6/6/2009 12:19 PM Nick Burgess said... Thank you. The data is pretty much random throughout the csv's so I think I it would have to iterate over the entire rows . I need to search all .csv files in the current directory. I can get glob to return a list of files. How could I get csv.reader

Re: [Tutor] converting xls to csv

2009-06-06 Thread Nick Burgess
Thank you. The data is pretty much random throughout the csv's so I think I it would have to iterate over the entire rows . I need to search all .csv files in the current directory. I can get glob to return a list of files. How could I get csv.reader to open all the files in the list? My loop

Re: [Tutor] converting xls to csv

2009-05-31 Thread Richard Lovely
2009/5/31 Nick Burgess : > 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) > > Alternatively, if you know that the string you want to search for only appears in a sin

Re: [Tutor] converting xls to csv

2009-05-31 Thread Nick Burgess
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 wrote: > Thank you for your response and my apologies for the non-useful > out

Re: [Tutor] converting xls to csv

2009-05-31 Thread Nick Burgess
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

Re: [Tutor] converting xls to csv

2009-05-31 Thread Alan Gauld
"Nick Burgess" 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!

[Tutor] converting xls to csv

2009-05-30 Thread Nick Burgess
Hi list, 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" code: #!/usr/bin/python import cvs def convertXLS2CSV(aFile): '''converts a MS Excel file to csv w/ the same n