question about class methods
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Mar 14 18:19:38 EDT 2007
In <et9o1i$qfi$1 at ruby.cit.cornell.edu>, Darren Dale wrote:
> I've run across some code in a class method that I don't understand:
>
> def example(self, val=0)
> if val and not self:
> if self._exp < 0 and self._exp >= -6:
>
> I am unfamiliar with some concepts here:
>
> 1) Under what circumstances would "if not self" be True?
If an object is "true" is determined either by a `__nonzero__()` method
that returns `True` or `False` or a `__len__()` method where anything
except 0 means "true".
> 2) If "not self" is True, how can self have attributes?
Attributes are independent from the "truth" value of an object.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list