[Tutor] Scope and elegance

Kent Johnson kent37 at tds.net
Mon Jan 7 22:13:40 CET 2008


Marc Tompkins wrote:
> I'd like to get the party line on this as well.  For a while now, I've 
> made a habit of defining an empty class called Global (Mr. Newton's 
> could be called Board, of course) at the top of my apps, and using its 
> attributes as if they were global variables.  It works, of course, but 
> it feels a bit... dirty.  Is there a more orthodox way to handle it?  Of 
> course, it would be optimal to remove any need for globals...

We had a discussion pretty recently on the evils of global variables:
http://thread.gmane.org/gmane.comp.python.tutor/44760

In most cases there is a better way, either direct parameter passing or 
instance attributes. Without seeing some code it's hard to make a 
suggestion, though.

Kent


More information about the Tutor mailing list