Steven Bethard said unto the world upon 2005-02-18 13:58:
I have two classes that implement the same interface, e.g. something like:

class C(object):
    def foo(self):
        """Foo things"""
        ...
    def bar(self):
        """Bar things"""
        ...
    def baz(self):
        """Baz things in a C manner"""
        ...

class D(object):
    def foo(self):
        """Foo things"""
        ...
    def bar(self):
        """Bar things"""
        ...
    def baz(self):
        """Baz things in a D manner"""
        ...

It bothers me that I'm basically writing the same docstrings multiple times. I guess what I really want to do is just write the docstrings for the interface I'm describing, and only supply docstrings in the classes when they need to differ from the interface docstrings.

Is there a good way to do this? If it's necessary, I can have C and D inherit from another class...

STeVe

Hi, I'm new to thinking in classes, and may not have understood your need. But does this help:


IDLE 1.1
>>> class Spam:
        '''I'm a very spammy docstring'''
        pass

>>> class Ham:
        __doc__ = Spam.__doc__

        
>>> help(Ham)
Help on class Ham in module __main__:

class Ham
 |  I'm a very spammy docstring

>>>

best,

Brian vdB

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to