[Tutor] Program Review: startup_user script -and- TimedMultiChoiceDialog class

2008-01-20 Thread ethan s
Hi folks. I'd love some feedback for two scripts. -startup_user: Intended to be called from a users logon script to present a list of apps to launch. List items can be set to default on or off. I run it from my system logon script like this: if exist "c:\_utils\scripts\logon_%USERNAME%.py" pytho

Re: [Tutor] Program review

2008-01-07 Thread Kent Johnson
Ricardo Aráoz wrote: > looking at the simpler use, if you would have exception handling in : > > try : > with open('/etc/passwd', 'r') as f: > for line in f: > print line > ... more processing code ... > except ExceptionsOnOpening : > ... exception handling

Re: [Tutor] Program review

2008-01-07 Thread Ricardo Aráoz
Torsten Marek wrote: >> try : >> with open('/etc/passwd', 'r') as f: >> for line in f: >> print line >> ... more processing code ... >> except ExceptionsOnOpening : >> ... exception handling >> except : >> ... exceptions inside the for >> >> >> >> Whereas

Re: [Tutor] Program review

2008-01-07 Thread Torsten Marek
On Mo, 2008-01-07 at 21:15 -0300, Ricardo Aráoz wrote: > Kent Johnson wrote: > > Ricardo Aráoz wrote: > >> PEP 0343 is not an > >> example of clarity in the definition of a statement, it mixes > >> justification with historic development with definition with actual > >> equivalent code. Couldn't o

Re: [Tutor] Program review

2008-01-07 Thread Ricardo Aráoz
Kent Johnson wrote: > Ricardo Aráoz wrote: >> Kent Johnson wrote: >>> from contextlib import nested >>> with nested(open_file(self.direcciones), open_file(self.excluidas)) >>> as (fIncl, fExcl): >>> >> Nice! How would you add exception reporting to this? > > I don't have a good answer to tha

Re: [Tutor] Program review

2008-01-07 Thread Ricardo Aráoz
Kent Johnson wrote: > Ricardo Aráoz wrote: >> PEP 0343 is not an >> example of clarity in the definition of a statement, it mixes >> justification with historic development with definition with actual >> equivalent code. Couldn't or wouldn't bother to understand it. > > Here is a better starting p

Re: [Tutor] Program review

2008-01-07 Thread Kent Johnson
Ricardo Aráoz wrote: > Kent Johnson wrote: >> from contextlib import nested >> with nested(open_file(self.direcciones), open_file(self.excluidas)) >> as (fIncl, fExcl): >> > > Nice! How would you add exception reporting to this? I don't have a good answer to that, that's why I didn't propos

Re: [Tutor] Program review

2008-01-07 Thread Kent Johnson
Ricardo Aráoz wrote: > PEP 0343 is not an > example of clarity in the definition of a statement, it mixes > justification with historic development with definition with actual > equivalent code. Couldn't or wouldn't bother to understand it. Here is a better starting point: http://docs.python.org/w

Re: [Tutor] Program review

2008-01-07 Thread Ricardo Aráoz
Kent Johnson wrote: > Jeff Younker wrote: > >> Or if you're using python 2.5 then you can use with statements: >> >> from __future__ import with_statements >> from contextlib import closing >> ... >> def mails(self): >> with closing(open_file(self.direcciones)) as fIncl: >>with clo

Re: [Tutor] Program review

2008-01-07 Thread Ricardo Aráoz
Jeff Younker wrote: >> Maybe it is my poor understanding of exception handling. My intention >> here is to open the first file, if error then report in logging and >> finish normally, else open the 2nd file, if error then report in >> logging >> close the 1st file and finish normally. If no error

Re: [Tutor] Program review

2008-01-07 Thread Kent Johnson
Jeff Younker wrote: > Or if you're using python 2.5 then you can use with statements: > > from __future__ import with_statements > from contextlib import closing > ... > def mails(self): > with closing(open_file(self.direcciones)) as fIncl: >with closing(open_file(self.excluidas))

Re: [Tutor] Program review

2008-01-06 Thread Jeff Younker
> > Maybe it is my poor understanding of exception handling. My intention > here is to open the first file, if error then report in logging and > finish normally, else open the 2nd file, if error then report in > logging > close the 1st file and finish normally. If no error then process. > Right

Re: [Tutor] Program review

2008-01-06 Thread Ricardo Aráoz
Ok, now the "tested" version (has been corrected) : #!/usr/bin/env python import time import smtplib import email import ConfigParser import logging class Mensaje(object) : def __init__(self) : cfg = ConfigParser.ConfigParser() try : cfg.readfp(open('config.cfg'))

Re: [Tutor] Program review

2008-01-06 Thread Ricardo Aráoz
Jeff Johnson wrote: > I would like to "butt" in here and mention that this is some of the most > useful information I have seen! I am a programmer of 25 years that is > new to Python. This type of back and forth dialog on actual production > code is extremely useful to learning the language.

Re: [Tutor] Program review

2008-01-06 Thread Ricardo Aráoz
Ok, new version. In procesar() I tried getting rid of the outer try block and having 'return' instead of 'raise' in the inner try blocks but I didn't like the result. I'd rather have one more indent level but have only one exit point from the function. Redesigned class Mensaje so that it now includ

Re: [Tutor] Program review

2008-01-06 Thread Ricardo Aráoz
Kent Johnson wrote: > Ricardo Aráoz wrote: >> Jeff Younker wrote: > >>> The enclosing try block isn't needed. More on this later. > >> Maybe it is my poor understanding of exception handling. My intention >> here is to open the first file, if error then report in logging and >> finish normally,

Re: [Tutor] Program review

2008-01-06 Thread Kent Johnson
Ricardo Aráoz wrote: > Jeff Younker wrote: >> The enclosing try block isn't needed. More on this later. > Maybe it is my poor understanding of exception handling. My intention > here is to open the first file, if error then report in logging and > finish normally, else open the 2nd file, if erro

Re: [Tutor] Program review

2008-01-06 Thread Ricardo Aráoz
Jeff Younker wrote: > The procesar function is complicated. It tries to do several things > that that are better done elsewhere. It needs to be broken up into > several functions and methods. This also clarifies and isolates the > exception handling. > >> def procesar(mensaje): >>try : >

Re: [Tutor] Program review

2008-01-05 Thread Jeff Younker
The procesar function is complicated. It tries to do several things that that are better done elsewhere. It needs to be broken up into several functions and methods. This also clarifies and isolates the exception handling. > def procesar(mensaje): >try : The enclosing try block isn't need

Re: [Tutor] Program review

2008-01-05 Thread Jeff Johnson
I would like to "butt" in here and mention that this is some of the most useful information I have seen! I am a programmer of 25 years that is new to Python. This type of back and forth dialog on actual production code is extremely useful to learning the language. I have done this with Ed Le

Re: [Tutor] Program review

2008-01-05 Thread Ricardo Aráoz
Kent Johnson wrote: > Ricardo Aráoz wrote: >> Ok, here is a corrected new version, I hope. >> >> Kent, the fact that Mensaje.__init__ reads the message configuration is >> by design (it's a feature, not a bug ;c) ). > > You misunderstood my suggestion. I would add a method to Mensaje that > creat

Re: [Tutor] Program review

2008-01-05 Thread Kent Johnson
Ricardo Aráoz wrote: > Ok, here is a corrected new version, I hope. > > Kent, the fact that Mensaje.__init__ reads the message configuration is > by design (it's a feature, not a bug ;c) ). You misunderstood my suggestion. I would add a method to Mensaje that creates the email.MIMEMultipart.MIME

Re: [Tutor] Program review

2008-01-05 Thread Ricardo Aráoz
Ok, here is a corrected new version, I hope. Kent, the fact that Mensaje.__init__ reads the message configuration is by design (it's a feature, not a bug ;c) ). The class is meant to be instantiated for using only once and with only one configuration and one message so including the configuration

Re: [Tutor] Program review

2008-01-05 Thread Ricardo Aráoz
Thanks everyone for your feedback. I'll correct the code and re-post it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Program review

2008-01-04 Thread Kent Johnson
Ricardo Aráoz wrote: > except Exception, e : > logging.error('No pude leer "config.cfg" : %s', e.strerror) You might like to use logging.error('No pude...', exc_info=True) which will include the full traceback in the log. You can use the exc_info keyword with any of the lo

Re: [Tutor] Program review

2008-01-04 Thread Tiger12506
> This~~ works, but may be a little inefficient. Especially the double > addr.strip() here. Given, it doesn't really matter, but I like even better > Perhaps a use of sets here... particularly intersection somehow... Whoops, I'm not versed in sets (blush) I meant difference_update _

Re: [Tutor] Program review

2008-01-04 Thread Tiger12506
uble addr.strip() here. Given, it doesn't really matter, but I like even better Perhaps a use of sets here... particularly intersection somehow... - Original Message - From: "Ricardo Aráoz" <[EMAIL PROTECTED]> To: Sent: Friday, January 04, 2008 6:47 PM Subject: [T

[Tutor] Program review

2008-01-04 Thread Ricardo Aráoz
Considering we are reviewing programs I'd like to submit one of mine and I would be thankful for any critic/improvement you can suggest. My ex needs to send mails to a long list of customers, problem is that she can not send more than 70 every 10 minutes or her ISP will consider her a spammer. So s