utility functions within a class?

John Salerno johnjsal at NOSPAMgmail.com
Mon May 8 00:06:54 EDT 2006


blair.bethwaite at gmail.com wrote:

> I'm having trouble deciphering what this bit means - "but these
> functions will be called from another method in the class, not from the
> instance itself", I don't think it makes sense.

Yeah, I'm starting to see that as I tried to implement it. Here's what I 
came up with, which works:

def generate(self, filename):
     self.head = self.generate_head()
     self.body = self.generate_body()

So the two generate_* methods are called from within another class 
method, and it seemed necessary to still call them from an instance. 
What I originally meant was that they would not be called from an 
instance *outside* the class itself, i.e. they won't be used when 
writing another script, they are only used by the class itself.



More information about the Python-list mailing list