Global Variables in OOP and Python
- From: "newbie" <solaris_1234@xxxxxxxxx>
- Date: 30 Dec 2005 15:03:54 -0800
Hello,
I have questions about global variables in OOP (in general) and Python
(in specific). I understand (I think) that global variables are
generally not a good idea. However, if there are variables that need to
be accessed by a number of classes that exists in separate namespaces
(files), what would be the best way to do this?
So far, I have approached the problem by making the variables
attributes of one class and passing instances of the class as variables
to the other class' methods.
The other way I thought of is to create a separate class that consists
of the variables and to use the
from <file name> import *
in all of the files (namespaces) where it is needed.
Is there a better way?
Are the two ideas presented above acceptable? If so, is one better than
the other from an OOP POV?
.
- Follow-Ups:
- Re: Global Variables in OOP and Python
- From: Gary Herron
- Re: Global Variables in OOP and Python
- From: Mike Meyer
- Re: Global Variables in OOP and Python
- From: Steven D'Aprano
- Re: Global Variables in OOP and Python
- Prev by Date: python encoding bug?
- Next by Date: Re: IRC sockets and queries
- Previous by thread: python encoding bug?
- Next by thread: Re: Global Variables in OOP and Python
- Index(es):
Relevant Pages
|