How can I test if a reference is null ?

Alex Martelli aleax at aleax.it
Thu Mar 27 10:50:01 EST 2003


cudjoe wrote:

> On a Java GUI, I need to test if a label contains an Icon, I wrote
> those few lines in Jython (similar):
> 
> 
> tabComp = panel.getComponents()
> trouve = false
> for com in tabComp:
>      if isinstance(com, JLabel):
>           icon = com.getIcon()
>           if( icon != NULL ): ##### doesn't work !
>                trouve = true
> 
> I know that there are no types in python, but how can we test if a
> variable is empty ?

I believe the test you want is

    if icon is not None:

(no redundant parentheses please!).  Can't check 'cause my
Jython has mysteriously broken recently, but...


Alex





More information about the Python-list mailing list