Request for criticism - tell me how to become more Pythonic

Jon spam_buster_2000 at yahoo.com
Mon Sep 10 17:21:50 EDT 2001


In article <9nj0tk$v2o$1 at slb2.atl.mindspring.net>, 
dalke at dalkescientific.com says...
> Jon:
> > If anyone has the time, I'd be interested in comments
> > about my style: what I am doing right, and what I need
> > to improve.
> 

Thanks to everyone that responded to my post (particularly Andrew Dalke, 
who seems to have spent far too much of his own precious time reading my 
horrible code :).

I've suddenly become a lot busier than I expected, so I won't have time 
to read everything you have written for the last couple of days. However, 
a couple of points --

1) This wasn't supposed to indicate how I write an immaculate, designed 
from the beginning piece of code. It was a challenge I set myself, to see 
whether I could write something in Python in a way that seemed 'obvious' 
to me, and actually have it work (which it did :). As others have pointed 
out, there are many ways I could refactor the code -- and as soon as my 
workload drops I probably will.

Responses to Andrew's comments:

2) 
> You could also recast your input code as a reader

Very good idea, and the skeleton code after is just the pointer I was 
looking for. As someone else noted, I'm orginally a C coder, and haven't 
really immersed myself in OO (apart from an optional software engineering 
course I took back when I was an undergrad). From my brief skimming, 
Python's approach to OO feels more like Pascal (or Modula-2) than C++ -- 
which is a good thing :). 

3)
>>              for (option, value) in options.items():
>>                     globals()[option] = value
>Very non-Pythonic. 

Sorry :). And looking at it with the benefit of sleep, you are right -- 
it's ugly and I should be ashamed. I still think Python is funky for 
allowing you to do this, however.

4) Particular thanks for your suggestions regarding how to deal with 
command line parsing -- again, I did it in the way that seemed obvious to 
me at the time. I am sure that, after close reading, your way will become 
obvious... 

'it won't take you more than a week of analysis to conclude that this is 
obvious' as a lecturer of mine once said... :)





More information about the Python-list mailing list