Establishing if an Object is Defined

Laurent Pointal laurent.pointal at limsi.fr
Wed Jan 10 10:20:55 CET 2007


bg_ie at yahoo.com a écrit :
> Hi,
> 
> The following code works -
> 
> one = 1
> if one == 1:
>   ok = 1
> print ok
> 
> but this does not, without exception -
> 
> one = 2
> if one == 1:
>   ok = 1
> print ok
> 
> How do I establish before printing ok if it actually exists so as to
> avoid this exception?

ok = 0
...do the job...

Very simple, failure-proof, no special case.





More information about the Python-list mailing list