How to set local variables in a method

Courageous jkraska at san.rr.com
Tue Jan 29 11:45:31 EST 2002


>I intend to set the variables a and b in the getvalues method.. Does
>anyone know how to do this??
>
>class test:
> 	def calculate(self):
> 		a,b = 0,0
> 		z = # what to put here???
> 		self.getvalues(z)
> 		print a + b 
> 	def getvalues(self,z):
> 		z['a'] = 2

Answer:

>>> def f(): print f.a

>>> f.a = 3
>>> f()
3
>>> 

This really isn't the right way to go about things, though. Keep in mind
that this data is essentially "static", as in common to all instances of
the function, from wherever it's called.

C//




More information about the Python-list mailing list