what's the best way to call a method of object without a guarantee of its existence

Leon QJing.Li at gmail.com
Tue May 5 06:05:51 EDT 2009


One way,  define the object before it is used,
like this:
object = None
.....
.....

if object is not None:
   object.method()

The other way, using try ... catch
try:
     object.method()
catch NameError:
     pass

for  big programs, which is better, or any other way?

Miles





More information about the Python-list mailing list