Why doesn't default property invoke for if statement?
Andreas Kostyrka
andreas at mtg.co.at
Sun Jan 6 12:54:15 EST 2002
On Wed, 12 Dec 2001 16:02:49 GMT
"Duffy O'Craven" <dufw1 at quinda.com> wrote:
> When using my component, I am hoping to avoid making script writing
> error-prone. So I want to require exactly the same expression for print as
> for anywhere else in the script. But I am also hoping that reference to an
> object, which in many contexts is just a boolean, can use the default
> binding id(0) aspect of COM. Unfortunately
>
> if Trans.Status.Value:
> print Trans.Status
>
> print "case 2",
> if 0 != Trans.Status:
> print Trans.Status
>
> print "case 3",
> if Trans.Status:
> print Trans.Status
>
> prints
> case 2 0
> case 3 0
>
> I think that print Trans.Status
> invokes the default property of Status, which is Status.Value, but
> I think that if Trans.Status:
> does not.
Well, print applies str() to the object. Basically,
you could change the if statement as follows:
if "0" != str(Trans.Status):
...
Actually, I don't see a possibility to achieve your goal. (There might be
some possibilities, but for them I know not enough about Win32/COM ;) )
Andreas
More information about the Python-list
mailing list