How to use a parameter in a class

Gary Herron gherron at islandtraining.com
Sat May 3 11:11:12 EDT 2008


Decebal wrote:
> I have the following class:
> #####
> class Dummy():
>     value = 0
>     def __init__(self, thisValue):
>         print thisValue
>         self.value = thisValue
>         value = thisValue
>
>     def testing(self):
>         print 'In test: %d' % self.value
>
>     def returnValue(self):
>         return self.value
>
>     result = someFuntion(default = value)
>   

But of course it doesn't work, as it tries to call someFunction and no 
such thing is define anywhere. 

But that can't be the answer to the *real* question you are trying to 
ask.  Why don't you tell us what you are trying to do here, and we'll 
wee if we can help.

Gary Herron


P.S.  Having a class attribute AND an instance attribute, both named 
"value" is going to cause trouble.

>
>
> #####
>
> But the last line does not work.
> I would like to do a call like:
>     dummy = Dummy(thisValue = 12)
>
> And that someFunction gets a default value of 12. How can I do that?
> --
> http://mail.python.org/mailman/listinfo/python-list
>   




More information about the Python-list mailing list