python:如果我只导入而不是运行模块,如何避免NonImplentedError?

kak*_*kyo 0 python import exception

我有这样一个类似接口的函数:

# 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
Run Code Online (Sandbox Code Playgroud)

现在,当我导入此模块时,我立即得到NotImplementedError,因此我无法使用SimpleParser.我怎么能使用这个例外习惯用法仍然可以使用它?

谢谢!

Ign*_*ams 6

你的缩进是愚蠢的,混合空格和标签.使用python -tt来验证.