[Tutor] Style/Conceptual Help

Rob Dowell rob at customdatasoft.com
Thu Nov 3 02:45:40 CET 2005


Thanks for the input Danny. I had already begun to separate the 
presentation layer from the computation by moving code out of the button 
click function. Your idea of a separate config class is a good one and I 
will implement it soon. I'll also begin fragmenting the function that 
does all the work to make it easier to follow. Thanks again for the 
input and I will post back here for more advice when I get these changes 
completed.

Oh, and about the email addresses, ebgreen is an account I use when 
doing email via a web interface (i.e. I'm not at home) and this is my 
home address.

Rob

Danny Yoo wrote:

>On Wed, 2 Nov 2005 ebgreen at customdatasoft.com wrote:
>
>  
>
>>I would be interested in some input/suggestions on the pythonicness of
>>the way I did things and on style, or anything else you see that I can
>>improve.
>>    
>>
>
>Hi ebgreen,
>
>The only big thing I'd point out is that the buttonClick() method of the
>application is too big.  *grin*
>
>
>You may want to extract some of its functionality as separate methods. The
>overall movement of button1Click appears to be the following:
>
>### Pseudocode #####################
>def button1Click():
>    importConfigurationInformation()
>    getListOfFiles()
>    copyFilesToTargetDirectory()
>    deleteSourceFilesSafely()
>####################################
>
>I'm boxing things this way initially because the program's comments seem
>to favor it.
>
>
>The configuration information stuff might want to live in a separate
>class: I'm not sure if the GUI itself should be so intimately involved
>with the details of reading off a ConfigParser.  One possibility is to do
>something like this:
>
>
>##################################################################
>class Configuration:
>    def __init__(self, configfile):
>        parser = ConfigParser.ConfigParser()
>        parser.read(configfile)
>        self.sourcedirloc = parser.get("GetPics", "sourcedir")
>        self.targetdirloc = parser.get("GetPics", "targetdir")
>        self.deleteold = parser.get("GetPics", "deleteold")
>        self.extList = parser.get("GetPics",
>                                  "extensions").lower().split(",")
>##################################################################
>
>(For the moment, I'm stripping out the exception handling just to make
>this example simple:  you'll probably want to add it back later.)
>
>
>If we have something like this Configuration object, then we can use it
>as:
>
>###########################################
>def button1Click(self, event):
>    files = {}
>    nameList = []
>    config = Configuration("./GetPics.ini")
>
>    #OPen the source dir and get a list of the files making the new name and
>    #path as you go
>    sourcefiles = os.listdir(config.sourcedirloc)
>    ...
>###########################################
>
>
>That is, if we're careful about things, we can slowly extract blocks of
>code into separate classes and methods, and we'll make the code easier to
>read.
>
>The extraction above also makes it easier to see that it might even be
>possible to reorder the configuration reading part to some time even
>before buttons are clicked, since it doesn't really pay attention to
>anything else besides the filename './GetPics.ini'.
>
>
>Hope this helps!
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
>  
>



More information about the Tutor mailing list