Re: script files with python (instead of tcsh/bash)?

2009-03-25 Thread Esmail
Hello David, R. David Murray wrote: Esmail ebo...@hotmail.com wrote: Here's a more Pythonic way to do that: with open('somefile') as f: for line in f: if 'somestring' in line: #do something In other words, you don't have to read the lines into a list

Re: script files with python (instead of tcsh/bash)?

2009-03-25 Thread Peter Otten
Esmail wrote: Hello David, R. David Murray wrote: Esmail ebo...@hotmail.com wrote: Here's a more Pythonic way to do that: with open('somefile') as f: for line in f: if 'somestring' in line: #do something In other words, you don't have to

Re: script files with python (instead of tcsh/bash)?

2009-03-25 Thread Esmail
Peter Otten wrote: In this case I believe I needed the contents in a list because the line I was looking for was above one that I could easily identify. Ie, once I had the index, I could go back/up one index to find the line I needed to process. Here's one way to avoid the list: last_line =

Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread Esmail
MRAB wrote: Two quick questions: As a replacement for grep I would use the re module and its methods? What about awk which I regularly use to extract fields based on position but not column number, what should I be using in Python to do the same? Just use string slicing. Would that be

Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread Esmail
Hi Gabriel, Gabriel Genellina wrote: En Sun, 22 Mar 2009 11:05:22 -0300, MRAB goo...@mrabarnett.plus.com escribió: Esmail wrote: Nick Craig-Wood wrote: Esmail ebo...@hotmail.com wrote: .. As a replacement for grep I would use the re module and its methods? Perhaps; but strings have

Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread Esmail
Hello again Nick, thanks for the additional script example. I was able to put something together where I read the whole file into a list as a series of lines (via readlines()) and then loop through the lines seeing if the target string was in the line .. seems to have worked reasonably well. I

Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread Alan G Isaac
On 3/21/2009 9:26 AM Esmail apparently wrote: I also write out some gnuplot scripts that later get executed to generate .jpg images. See Gnuplot.py Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list

Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread Esmail
Alan G Isaac wrote: On 3/21/2009 9:26 AM Esmail apparently wrote: I also write out some gnuplot scripts that later get executed to generate .jpg images. See Gnuplot.py Thanks Alan, I will! Esmail -- http://mail.python.org/mailman/listinfo/python-list

Re: script files with python (instead of tcsh/bash)?

2009-03-23 Thread R. David Murray
Esmail ebo...@hotmail.com wrote: Hello again Nick, thanks for the additional script example. I was able to put something together where I read the whole file into a list as a series of lines (via readlines()) and then loop through the lines seeing if the target string was in the line ..

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread Nick Craig-Wood
Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? Yes! Right now I have a bigg'ish bash/tcsh script that contain some grep/awk command plus various files are processed and created, renamed and moved to specific directories. I also write out

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread Esmail
Nick Craig-Wood wrote: Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? Yes! .. Almost any script that contains a loop I convert into python. In any case, the scripts are starting to look pretty hairy and I was wondering if it would

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread MRAB
Esmail wrote: Nick Craig-Wood wrote: Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? Yes! .. Almost any script that contains a loop I convert into python. In any case, the scripts are starting to look pretty hairy and I was wondering

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread Gabriel Genellina
En Sun, 22 Mar 2009 11:05:22 -0300, MRAB goo...@mrabarnett.plus.com escribió: Esmail wrote: Nick Craig-Wood wrote: Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? Two quick questions: As a replacement for grep I would use the re module

Re: script files with python (instead of tcsh/bash)?

2009-03-22 Thread Nick Craig-Wood
Esmail ebo...@hotmail.com wrote: thanks for including the script, that really helps. Nice way of finding files. Python has lots of useful stuff like that! Two quick questions: As a replacement for grep I would use the re module and its methods? The re module works on strings not

script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
Hello all, I am wondering if anyone is using python to write script files? Right now I have a bigg'ish bash/tcsh script that contain some grep/awk command plus various files are processed and created, renamed and moved to specific directories. I also write out some gnuplot scripts that later

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Aahz
In article mailman.2374.1237641982.11746.python-l...@python.org, Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? These days, I always convert any even slightly complicated script to Python. I've looked around the web w/o much luck for some

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
Aahz wrote: In article mailman.2374.1237641982.11746.python-l...@python.org, Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? These days, I always convert any even slightly complicated script to Python. well .. that sounds encouraging ...

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Joe Riopel
On Sat, Mar 21, 2009 at 9:26 AM, Esmail ebo...@hotmail.com wrote: In any case, the scripts are starting to look pretty hairy and I was wondering if it would make sense to re-write them in Python. I am not sure how suitable it would be for this. Are these scripts run on computers that are

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
Hi Joe, Joe Riopel wrote: Are these scripts run on computers that are guaranteed to have Python installed? If not, can you install Python on them? I use Python when I can, but sometimes shell scripts just makes sense. T Yes. Currently I am running the bash/tcsh scripts under Ubuntu. The

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread D'Arcy J.M. Cain
On Sat, 21 Mar 2009 09:26:02 -0400 Esmail ebo...@hotmail.com wrote: Hello all, I am wondering if anyone is using python to write script files? All the time. Right now I have a bigg'ish bash/tcsh script that contain some grep/awk command plus various files are processed and created, renamed

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Aahz
In article mailman.2384.1237643720.11746.python-l...@python.org, Esmail ebo...@hotmail.com wrote: Aahz wrote: In article mailman.2374.1237641982.11746.python-l...@python.org, Esmail ebo...@hotmail.com wrote: I've looked around the web w/o much luck for some examples but come short. Any

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Peter Pearson
On Sat, 21 Mar 2009 09:26:02 -0400, Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? If it can be done in a few simple lines of shell script, fine: make it a shell script. But if it's more complex than that, Python is clearer. Just my two cents.

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
Aahz wrote: If you post a sample script you're trying to convert, you may get some responses that show how different people would write it in Python. That's a nice suggestion .. I may end up doing this after I do some readings, just wanted to make sure this is not too outlandish of an idea

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
Peter Pearson wrote: On Sat, 21 Mar 2009 09:26:02 -0400, Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? If it can be done in a few simple lines of shell script, fine: make it a shell script. But if it's more complex than that, Python is

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Ned Deily
In article gq2rjc$j...@ger.gmane.org, Esmail ebo...@hotmail.com wrote: Aahz wrote: In article mailman.2374.1237641982.11746.python-l...@python.org, Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? These days, I always convert any even

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread andrew cooke
Esmail wrote: Peter Pearson wrote: On Sat, 21 Mar 2009 09:26:02 -0400, Esmail ebo...@hotmail.com wrote: I am wondering if anyone is using python to write script files? If it can be done in a few simple lines of shell script, fine: make it a shell script. But if it's more complex than that,

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
Ned Deily wrote: Perhaps the recipe for Pyline might give you some ideas on how to write python scripts that play well with other scripts. http://code.activestate.com/recipes/437932/ ah .. very nice .. thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: script files with python (instead of tcsh/bash)?

2009-03-21 Thread Esmail
andrew cooke wrote: Esmail wrote: just a quick data point here - .. so you might be better spending the time improving your bash skills than doing what will be largely drudge work in a language you already know. I'll have to think about it .. at this point I know both languages about