question about globals vars...

Lee Harr missive at frontiernet.net
Sat Aug 3 01:19:05 CEST 2002


In article <aie61c$1368m5$1 at ID-146704.news.dfncis.de>, Shagshag13 wrote:
> hello,
> 
> i'm wondering when i should use globals or if i should avoid
 them by fair means...
> - so how do you use them or what mecanism do you use to avoid
 using them (in a class / in a function) ?
> - when you do OO style do you define some kind of parameters
 class, which you instanciate and use ?
> - is it a good idea to use a global as a flag : put it to 0 
or 1 in main and then testing in other functions/class and changing way
> of acting according to flag value ?
> - or should i prefer to only use globals as default value for 
other vars ?
> 


I am not sure this is relevant, but I recently was coding a game using
pygame and I found out I could store variables in classes. for instance:

class GameBoard:
    def __init__(self):
        GameBoard.height = 5
        GameBoard.width = 10

class Avatar:
    def __init__(self):
        self.x = GameBoard.width / 2
        self.y = GameBoard.height / 2



This is not a sterling example, but it gives an idea of what I
am talking about. So, instead of passing the particular instance
of the gameboard around all over the place, just put the vars
some place that makes sense.

This might be bad style. In fact I was planning on asking here
whether this is going to come back to haunt me in the future.

Any wisdom appreciated....




More information about the Python-list mailing list