Re: Evaluate my first python script, please

2010-03-05 Thread Tim Wintle
On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: I am looking for advice along the lines of an easier way to do this or a more python way (I'm sure that's asking for trouble!) or people commonly do this instead or here's a slick trick or oh, interesting, here's my version to do the same

Re: Evaluate my first python script, please

2010-03-05 Thread Jean-Michel Pichavant
Pete Emerson wrote: I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is perlesque This script parses /etc/hosts for hostnames, and based on terms given on

Re: Evaluate my first python script, please

2010-03-05 Thread Duncan Booth
Jean-Michel Pichavant jeanmic...@sequans.com wrote: You've already been given good advices. Unlike some of those, I don't think using regexp an issue in any way. Yes they are not readable, for sure, I 100% agree to that statement, but you can make them readable very easily. # not

Re: Evaluate my first python script, please

2010-03-05 Thread Jean-Michel Pichavant
Duncan Booth wrote: Jean-Michel Pichavant jeanmic...@sequans.com wrote: You've already been given good advices. Unlike some of those, I don't think using regexp an issue in any way. Yes they are not readable, for sure, I 100% agree to that statement, but you can make them readable very

Re: Evaluate my first python script, please

2010-03-05 Thread Duncan Booth
Jean-Michel Pichavant jeanmic...@sequans.com wrote: And tell me how not using regexp will ensure the /etc/hosts processing is correct ? The non regexp solutions provided in this thread did not handled what you rightfully pointed out about host list and commented lines. It won't make is

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
Thanks for your response, further questions inline. On Mar 4, 11:07 am, Tim Wintle tim.win...@teamrubber.com wrote: On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: I am looking for advice along the lines of an easier way to do this or a more python way (I'm sure that's asking for

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 7:00 am, Duncan Booth duncan.bo...@invalid.invalid wrote: Jean-Michel Pichavant jeanmic...@sequans.com wrote: And tell me how not using regexp will ensure the /etc/hosts processing is correct ? The non regexp solutions provided in this thread did not handled what you rightfully

Re: Evaluate my first python script, please

2010-03-05 Thread Tim Wintle
On Fri, 2010-03-05 at 07:53 -0800, Pete Emerson wrote: Thanks for your response, further questions inline. On Mar 4, 11:07 am, Tim Wintle tim.win...@teamrubber.com wrote: On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: I am looking for advice along the lines of an easier way to do

Re: Evaluate my first python script, please

2010-03-05 Thread sjdevn...@yahoo.com
On Mar 5, 10:53 am, Pete Emerson pemer...@gmail.com wrote: Thanks for your response, further questions inline. On Mar 4, 11:07 am, Tim Wintle tim.win...@teamrubber.com wrote: On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: I am looking for advice along the lines of an easier way to

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 10:19 am, sjdevn...@yahoo.com sjdevn...@yahoo.com wrote: On Mar 5, 10:53 am, Pete Emerson pemer...@gmail.com wrote: Thanks for your response, further questions inline. On Mar 4, 11:07 am, Tim Wintle tim.win...@teamrubber.com wrote: On Thu, 2010-03-04 at 10:39 -0800, Pete

Evaluate my first python script, please

2010-03-04 Thread Pete Emerson
I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is perlesque This script parses /etc/hosts for hostnames, and based on terms given on the command line (argv),

Re: Evaluate my first python script, please

2010-03-04 Thread MRAB
Pete Emerson wrote: I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is perlesque This script parses /etc/hosts for hostnames, and based on terms given on

Re: Evaluate my first python script, please

2010-03-04 Thread nn
On Mar 4, 2:30 pm, MRAB pyt...@mrabarnett.plus.com wrote: Pete Emerson wrote: I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is perlesque This

Re: Evaluate my first python script, please

2010-03-04 Thread Jonathan Gardner
On Thu, Mar 4, 2010 at 10:39 AM, Pete Emerson pemer...@gmail.com wrote: #!/usr/bin/python More common: #!/usr/bin/env python import sys, fileinput, re, os filename = '/etc/hosts' hosts = [] for line in open(filename, 'r'):        match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line)

Re: Evaluate my first python script, please

2010-03-04 Thread sjdevn...@yahoo.com
On Mar 4, 1:39 pm, Pete Emerson pemer...@gmail.com wrote: I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is perlesque This script parses /etc/hosts for

Re: Evaluate my first python script, please

2010-03-04 Thread Pete Emerson
Great responses, thank you all very much. I read Jonathan Gardner's solution first and investigated sets. It's clearly superior to my first cut. I love the comment about regular expressions. In perl, I've reached for regexes WAY too much. That's a big lesson learned too, and from my point of view