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

Marco Mariani marco at sferacarta.com
Wed May 6 06:21:45 EDT 2009


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):
         pass


> actually, the module including "parent' class works very well
> without those definitions, from parent class's point of view,
> those definitions are kind of noisy.

If you don't feel the need to define the instances there, maybe they 
don't belong to that class after all.





More information about the Python-list mailing list