can i implement virtual functions in python ?

Andrew Dalke adalke at mindspring.com
Wed Oct 1 16:30:01 EDT 2003


Me:
> > However, I do use NotImplementedError so the exception
> > which percolates up is more obvious than AttributeError.  It also
> > allows me to put in a docstring describing the interface requirements
> > of derived classes.

logistix at cathoderaymission.net:
> Either using hasattr or or a try...except clause gets a little clunky.
>  I'd just rather do something like:
>
> class abstract:
>     def a(self): raise NotImplementedError("Virtual Method")
>     def b(self): raise NotImplementedError("Virtual Method")
>     def c(self): raise NotImplementedError("Virtual Method")

Well, I agreed with you ;)

I think this is the right way, and it lets you include a
docstring to describe the interface better.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list