use var to form name of object

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Jul 6 05:44:11 EDT 2006


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



More information about the Python-list mailing list