Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller
Sorry, should have included a concrete example. Although, as the others have said, I'm not sure how it helps with what you (seem) to want to do. 0 % cat bar.py def the_answer(self): return 42 0 % cat foo.py import bar class A: pass setattr(A, '__call__', bar.the_answer) a=A() print a(

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Chris Fuller
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

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Steven D'Aprano
On Sun, 11 Apr 2010 10:30:54 pm 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 mo

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Alan Gauld
"Ray Parrish" wrote 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. OK, Kind of... In other words, if I do the import of module ISPdetector, I want to

Re: [Tutor] Declaring methods in modules.

2010-04-11 Thread Patrick Sabin
ipAddress = "123.123.123.123" emails = ipAddress.GetEmailAddresses() Not exactly sure, what you want, but maybe something like this? class mystr(str): def GetEmailAddresses(self): return [str(self)] ipAddress = mystr("123.123.123.123") emails = ipAddress.GetEmailAddresses()