Re: Overloading "if object" unary operator

2006-11-29 Thread Fredrik Lundh
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

Re: Overloading "if object" unary operator

2006-11-29 Thread Sarcastic Zombie
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

Re: Overloading "if object" unary operator

2006-11-29 Thread Peter Otten
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

Re: Overloading "if object" unary operator

2006-11-29 Thread Roberto Bonvallet
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

Overloading "if object" unary operator

2006-11-29 Thread Sarcastic Zombie
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