[Tutor] Declaring methods in modules.

Chris Fuller cfuller084 at thinkingplanet.net
Sun Apr 11 18:41:08 CEST 2010

This actually isn't so hard with classes (not instances of the class).  Just 
use setattr().  The first parameter of the function will be the instance, 
called "self" by convention.  This should work with both old and new style 
There's stuff in the new module for adding stuff to instances, but I haven't 
played around with it recently.  A little fiddling around in the interactive 
interpreter should clear up anything you're uncertain about, though.


On Sunday 11 April 2010, Ray Parrish wrote:
> Hello,
> I am working on some stuff, and I would like to be able to write a
> module which can be imported, and after it's been imported I would like
> to be able to access it's functions as methods.
> In other words, if I do the import of module ISPdetector, I want to then
> be able to make calls like the following -
>     ipAddress = ""
>     emails = ipAddress.GetEmailAddresses()
> where GetEmailAddresses() is defined in module ISPdetector. Do I just
> wite that function in ISPdetector.py as a normally deffed function, or
> does it have to be part of a class within the module?
> Thanks for any help you can be.
> Later, Ray Parrish

More information about the Tutor mailing list