use var to form name of object

gel geli at tasmail.com
Mon Jul 17 19:16:58 EDT 2006


Marc 'BlackJack' Rintsch wrote:

> In <1152154206.733757.79950 at a14g2000cwb.googlegroups.com>, gel wrote:
>
> > Yeah I am still getting my head around things... not exactly sure what
> > you where saying about the globals, but this works
> >
> >
> > global k
> > k = 5
> > class foo:
> >
> >         def wow(self, n):
> >                 global k
> >                 k += n
> >                 return k
> >
> >
> > f=foo()
> > f.wow(55)


>
> The first ``global`` does nothing.  ``global`` at module level makes no
> sense.  And the snippet could be easily written without assigning to
> global names from within a function/method:
>
> k = 5
> class Foo:
>     def wow(self, n):
>         return k + n
>
> f = Foo()
> k = f.wow(55)
> 
> Ciao,
> 	Marc 'BlackJack' Rintsch

Ah yes, thanks for that Marc




More information about the Python-list mailing list