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

2009-05-06 Thread Marco Mariani
Leon wrote: So I need to go back to the module including "parent" class to define the objects that I maybe use in future as None, You can assign them to a placeholder, with a method that always exists but does nothing. class NullObject(object): def method(self, *args, **kw): pas

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

2009-05-05 Thread Leon
On May 5, 3:25 am, Marco Mariani wrote: > Leon wrote: > > One way,  define the object before it is used, > > like this: > > object = None > > This is a good practice anyway. Conditional existance of objects is > quite evil. Resorting to if defined('foo') is double-plus-ugly. This was why I asked

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

2009-05-05 Thread Marco Mariani
Leon wrote: One way, define the object before it is used, like this: object = None This is a good practice anyway. Conditional existance of objects is quite evil. Resorting to if defined('foo') is double-plus-ugly. The other way, using try ... catch try: object.method() catch NameEr

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

2009-05-05 Thread Leon
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 -- http://mail.pyth