[Tutor] One shared object. class attribute or global variable?

Python python at venix.com
Sat Mar 4 02:26:04 CET 2006


On Sat, 2006-03-04 at 00:42 +0000, Adam wrote:
> On 04/03/06, Adam <adam.jtm30 at gmail.com> wrote:
> > I've got a module that needs to share a pack of cards
> >
> > pack = ["14s", "2s", "3s", "4s", "5s", "6s", "7s", "8s", "9s", "10s", "11s",
> >     "12s", "13s", "14d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "10d",
> >     "11d", "12d", "13d", "14c", "2c", "3c", "4c", "5c", "6c", "7c", "8c", "9c",
> >     "10c", "11c", "12c", "13c", "14h", "2h", "3h", "4h", "5h", "6h", "7h", "8h",
> >     "9h", "10h", "11h", "12h", "13h"]
> > random.shuffle(pack)
> >
> > do you think it is worth making a class with just this attribute or
> > would this be a good place to use a global variable?
> >
> 
> I just realised this probably isn't as clear as it should be, sorry
> it's late. It needs to share the variable with the functions (or
> methods) in the module not with anything outside of it.

It looks like this will be shared and modified.  In general, I think
read-only variables (initialized at start-up when not constants) can
work OK as globals.  A container that will be changed and shared should
almost certainly go in a class.

> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list