How can I test if a reference is null ?
peter at engcorp.com
Thu Mar 27 20:04:37 CET 2003
> cudjoe at europe.com (cudjoe) wrote in message news:<b1177e67.0303270740.34de715b at posting.google.com>...
> > 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 ?
> > Thanks you everybody,
> > Mathieu
> if vars().has_key('icon'):
> print 'not empty'
This is surely not the same thing as what the OP intended. If the
com.getIcon() routine doesn't manage to return anything, even None,
then it must have raised an exception and your test would never
be executed anyway.
Alex was indubitably on the right path as usual...
More information about the Python-list