Sarcastic Zombie wrote:
> If I have a class
>
> class A:
> __init__(id)
> self.id = id
>
> is there any way to overload the 'if' unary usage to detect if a
> variable has a value?
http://effbot.org/pyref/__nonzero__
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 29, 11:26 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> Sarcastic Zombie wrote:
> > is there any way to overload the 'if' unary usage to detect if a
> > variable has a value?Define a __nonzero__() or __len__() method.
>
> Peter
Thanks to both of you, it worked perfectly. I must have missed
Sarcastic Zombie wrote:
> is there any way to overload the 'if' unary usage to detect if a
> variable has a value?
Define a __nonzero__() or __len__() method.
Peter
--
http://mail.python.org/mailman/listinfo/python-list
Sarcastic Zombie wrote:
> For example, in the code:
>
> a = A(56)
> if a:
>print "Hoo hah!"
>
> how can I insure that the if will come back true and fire off the print
> if and only if self.id is defined? I want to do this in an overloaded,
> generic way, if possible; I know that I could test
Good morning,
If I have a class
class A:
__init__(id)
self.id = id
is there any way to overload the 'if' unary usage to detect if a
variable has a value?
For example, in the code:
a = A(56)
if a:
print "Hoo hah!"
how can I insure that the if will come back true and fire off th