On 07/14/2013 04:27 AM, Jim Mooney wrote:
On 13 July 2013 22:16, Dave Angel <da...@davea.name> wrote:
That's monkey-patching. You're reaching inside the module and modifying
it.
That's interesting. I saw that phrase and wondered what it was. Now I know
;') Actually, I did refactor the numbers program into disparate functions.
That's why I started using main(), so I could import it and just use the
functions. That test would have been impossible if everything was still
mashed up. In fact, once I refactored, I saw how easy it would be to test
like that. But callbacks look interesting. I'll have to try them.
Note that callbacks is just one approach to writing flexible modules.
Another approach is writing the behavior into a class which may be
subclassed. The user then writes a subclass in which he/she has written
some overriding methods.
If you want to see a sample of how these are done, study any GUI library.
Except using a callback would mean editing the inputter module, which I am
pretending is some module code I'm importing but don't want to mess with.
Exactly. So you're simulating what it's like to use a module whose
author didn't plan ahead for your particular type of customization.
So I just import it and do the so-called monkey patch without actually
editing the module. My thought was I could do quick tests and dummy inputs
without changing the module itself.
--
DaveA
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor