0

I have an interface-like function implemented this way:

# File: parsers.py
class BaseParser(object):
    '''Interface class'''
    def __init__(self):
        self.content

    def Parse(self):
        """The interface, not implemented"""

        raise NotImplementedError('{}.Parse()'.format(inspect.stack()[0][3]))

class SimpleParser(BaseParser):
    '''Implementation class'''
    def __init__(self):
        BaseParser.__init__(self)

    def Parse(self):
        # Do real work

Now when I import this module, I get NotImplementedError right away so I can't use SimpleParser. How could I use this exception idiom and still be able to use it?

Thanks!

4

1 回答 1

6

Your indentation is goofed, mixing spaces and tabs. Use python -tt to verify.

于 2012-08-19T20:22:11.820 回答