Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 10:19 am, "sjdevn...@yahoo.com" wrote: > On Mar 5, 10:53 am, Pete Emerson wrote: > > > > > > > Thanks for your response, further questions inline. > > > On Mar 4, 11:07 am, Tim Wintle wrote: > > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > > I am looking for advice

Re: Evaluate my first python script, please

2010-03-05 Thread sjdevn...@yahoo.com
On Mar 5, 10:53 am, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07 am, Tim Wintle 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

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 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

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 7:00 am, Duncan Booth wrote: > Jean-Michel Pichavant 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 > >

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 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 trouble!) or > > "peo

Re: Evaluate my first python script, please

2010-03-05 Thread Duncan Booth
Jean-Michel Pichavant 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 automatically correct,

Re: Evaluate my first python script, please

2010-03-05 Thread Jean-Michel Pichavant
Duncan Booth wrote: Jean-Michel Pichavant 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 readable

Re: Evaluate my first python script, please

2010-03-05 Thread Duncan Booth
Jean-Michel Pichavant 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 readable > match = re.se

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 t

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

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

Re: Evaluate my first python script, please

2010-03-04 Thread sjdevn...@yahoo.com
On Mar 4, 1:39 pm, 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,

Re: Evaluate my first python script, please

2010-03-04 Thread Jonathan Gardner
On Thu, Mar 4, 2010 at 10:39 AM, Pete Emerson 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 nn
On Mar 4, 2:30 pm, MRAB 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 script parses /

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 t

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: Q's on my first python script

2009-05-14 Thread Marius Gedminas
On May 10, 6:56 pm, Steven D'Aprano wrote: > > 4. What's the python way to emit warnings?  (The script below should > >    warn the user that arguments after the first one are ignored.) > > import warnings > warnings.warn("The end of the world is coming!") The warnings module is used for warnings

Re: Q's on my first python script

2009-05-14 Thread Marius Gedminas
On May 11, 12:30 pm, Nick Craig-Wood wrote: >     def __init__(self): >         usage = '''Usage: %prog [options] YYMMDD >            %prog -h|--help > ''' >         parser = OptionParser(usage=usage) >         parser.add_option("-n", "--no-newline", dest="nonl", >                           action

Re: Q's on my first python script

2009-05-11 Thread Nick Craig-Wood
kj wrote: > > Below is my very firs python script. > > This was just a learning exercise; the script doesn't do anything > terribly exciting: for an argument of the form YYMMDD (year, month, > day) it prints out the corresponding string YYMMDDW, where W is a > one-letter abbreviation for th

Re: Q's on my first python script

2009-05-10 Thread kj
Thank you all very much! I really appreciate it. kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

Re: Q's on my first python script

2009-05-10 Thread kj
In <0216ec41$0$20647$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sun, 10 May 2009 12:52:21 +, kj wrote: >> 1. The name of the BadArgument exception class defined in the script >>does not seem to me sufficiently specific. If one were to import the >>script in order to reu

Re: Q's on my first python script

2009-05-10 Thread Dave Angel
kj wrote: Below is my very firs python script. This was just a learning exercise; the script doesn't do anything terribly exciting: for an argument of the form YYMMDD (year, month, day) it prints out the corresponding string YYMMDDW, where W is a one-letter abbreviation for the day of the week

Re: Q's on my first python script

2009-05-10 Thread MRAB
Andre Engels wrote: On Sun, May 10, 2009 at 5:56 PM, Steven D'Aprano wrote: 5. The variable wd is meant to be "global" to the script. In other languages I've programmed in I've seen some typographic convention used for the name of such variables (e.g. all caps) to signal this widened

Re: Q's on my first python script

2009-05-10 Thread Scott David Daniels
Steven D'Aprano wrote: On Sun, 10 May 2009 12:52:21 +, kj wrote: 5. The variable wd is meant to be "global" to the script. In other languages I've programmed in I've seen some typographic convention used for the name of such variables (e.g. all caps) to signal this widened sco

Re: Q's on my first python script

2009-05-10 Thread Andre Engels
On Sun, May 10, 2009 at 5:56 PM, Steven D'Aprano wrote: >> 5. The variable wd is meant to be "global" to the script.  In other >>    languages I've programmed in I've seen some typographic convention >>    used for the name of such variables (e.g. all caps) to signal this >>    widened scope.  Do

Re: Q's on my first python script

2009-05-10 Thread Steven D'Aprano
On Sun, 10 May 2009 12:52:21 +, kj wrote: > 1. The name of the BadArgument exception class defined in the script >does not seem to me sufficiently specific. If one were to import the >script in order to reuse its wkday_abbrev function, I'd like this >exception's name to be more un

Q's on my first python script

2009-05-10 Thread kj
Below is my very firs python script. This was just a learning exercise; the script doesn't do anything terribly exciting: for an argument of the form YYMMDD (year, month, day) it prints out the corresponding string YYMMDDW, where W is a one-letter abbreviation for the day of the week. E.g. % wd

Re: Request for tips on my first python script.

2006-09-09 Thread Steven Bethard
Lex Hider wrote: > try: > opts, args = getopt.getopt(sys.argv[1:], "l:", > ["latest=", "notfound"]) > except getopt.GetoptError: > sys.exit(2) > #usage() > > for opt, arg in opts: > if opt in (

Re: Request for tips on my first python script.

2006-09-08 Thread Roberto Bonvallet
Lex Hider wrote: > Any tips on the code quality and use of python would be appreciated. I've > got a feeling the overall structure is up the creek. [...] >for opt, arg in opts: >if opt in ("-l", "--latest"): >latest = int(arg) >elif opt in ("--notfound"): >

Re: Request for tips on my first python script.

2006-09-08 Thread Maric Michaud
Le vendredi 08 septembre 2006 13:56, Maric Michaud a écrit : > [EMAIL PROTECTED] jeu sep 07 09:17:51:~/test$ export HOME=/etc > [EMAIL PROTECTED] ven sep 08 13:53:17:/home/maric/test$ cd ~ > [EMAIL PROTECTED] ven sep 08 13:53:22:~$ pwd > /etc > [EMAIL PROTECTED] ven sep 08 13:55:46:~$ python -c 'im

Re: Request for tips on my first python script.

2006-09-08 Thread Maric Michaud
Le vendredi 08 septembre 2006 13:41, Sybren Stuvel a écrit : > > HOME = os.path.expanduser("~") > > I wouldn't use this. Just use os.environ['HOME']. In most cases it > turns out to be the same directory, but it adds more flexibility. If > someone wants your app to read/write to another directory,

Re: Request for tips on my first python script.

2006-09-08 Thread Sybren Stuvel
Lex Hider enlightened us with: > Any tips on the code quality and use of python would be appreciated. > I've got a feeling the overall structure is up the creek. I'll post some remarks about the code ;-) > HOME = os.path.expanduser("~") I wouldn't use this. Just use os.environ['HOME']. In most c

Re: Request for tips on my first python script.

2006-09-08 Thread Bruno Desthuilliers
Lex Hider wrote: > Hi, > Apologies if this is against etiquette. I've just got my first python app up > and running. It is a podcast aggregator depending on feedparser. I've really > only learnt enough to get this up and running. > > Any tips on the code quality and use of python would be apprec

Request for tips on my first python script.

2006-09-07 Thread Lex Hider
Hi, Apologies if this is against etiquette. I've just got my first python app up and running. It is a podcast aggregator depending on feedparser. I've really only learnt enough to get this up and running. Any tips on the code quality and use of python would be appreciated. I've got a feeling th

Re: My First Python Script

2005-09-16 Thread Ed Hotchkiss
Someone else actually got me some help, the end result he hooked me up with was:   # function to evaluate all possible IPs def findIPs(): ipFile = open("IPList.txt", 'w') for octet1 in range(256): for octet2 in range(256): for octet3 in range(256): for octet4 in range(256): ipAddress = '%03.d.%03.

Re: My First Python Script

2005-09-16 Thread John Hazen
* Ed Hotchkiss <[EMAIL PROTECTED]> [2005-09-15 20:36]: > But then I still get the error with the len(x) statement .. hmm Ahh. In the future, it will help us help you, if you make it clear that there was an error, and *paste the exact error* into your mail. For example, I'm guessing the error you

Re: My First Python Script

2005-09-16 Thread Ed Hotchkiss
  Sweet, time to play with python for a whole day today :P  On 9/16/05, Gary Wilson Jr <[EMAIL PROTECTED]> wrote: Ed Hotchkiss wrote:> def ZeroThrough255():>   x = 0>   while x <= 255: >   if len(x) == 1:>   mySet = '00' + str(x)>   elif len(x) ==

Re: My First Python Script

2005-09-16 Thread Gary Wilson Jr
Ed Hotchkiss wrote: > def ZeroThrough255(): > x = 0 > while x <= 255: > if len(x) == 1: > mySet = '00' + str(x) > elif len(x) == 2: > mySet = '0' + str(x) > else: > mySet = x >

Re: My First Python Script

2005-09-15 Thread Robert Kern
Ed Hotchkiss wrote: > But then I still get the error with the len(x) statement .. hmm That's because integers don't have a length. But if you follow James' advice, you don't need to calculate lengths of anything. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high

Re: My First Python Script

2005-09-15 Thread Ed Hotchkiss
But then I still get the error with the len(x) statement .. hmm     On 9/15/05, James Stroud <[EMAIL PROTECTED]> wrote: Try the % operator with strings.For instance: "%03.d" % 5py> "%03.d" % 5 '005'This operator, from what I have experienced, has the same properties as theunix printf. In python, I

Re: My First Python Script

2005-09-15 Thread James Stroud
Try the % operator with strings. For instance: "%03.d" % 5 py> "%03.d" % 5 '005' This operator, from what I have experienced, has the same properties as the unix printf. In python, I think its called "string formatting". James On Thursday 15 September 2005 20:33, Ed Hotchkiss wrote: > So I ha

My First Python Script

2005-09-15 Thread Ed Hotchkiss
So I have a  script, first part of a script that I am making to determine each possible combination of IP addresses that are out there.   This part is just to get the end of the IP (the last 3 digits). So, they are from 0 - 255. I just want to print 0 - 255, HOWEVER   If the number is only say ...