[Tutor] fetching wikipedia articles

Kent Johnson kent37 at tds.net
Fri Jan 23 13:27:40 CET 2009


On Fri, Jan 23, 2009 at 6:23 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:

> Rather than editing the existing code and making it non standard
> why not subclass robotparser:
>
> class WP_RobotParser(robotparser):
>   def __init__(self, *args, *kwargs):
>         robotparser.__init__(self, *args, *kwargs)
>         self.addheaders = .......blah....
>
> Thats one of the advantages of OOP, you can change the way
> classes work without modifying the original code. And thus not
> breaking any code that relies on the original behaviour.

That won't work, it is urllib.URLOpener() that he is patching and
robotparser does not supply a way to change the URLOpener subclass
that it uses.

Ken


More information about the Tutor mailing list