typeof foo == 'undefined' ???

Rainer Deyke root at rainerdeyke.com
Sat Nov 4 00:09:13 CET 2000

"Jay Chalfant" <jchalfan at outbackinc.com> wrote in message
news:jlHM5.33$934.1098 at news.callamer.com...
> Hello,
> This is a valid JavaScript expression:
> typeof foo == 'undefined'

type(foo) == 'undefined' is a valid Python expression, but it doesn't do
what you want it to do.

> and is useful in testing the existince of object member vars such as:
> if ( typeof foo.bar == 'undefined' )
>     print("I don't have that!")
> Is there an equivalent test in Python?

hasattr(foo, 'bar')

Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

More information about the Python-list mailing list