utility functions within a class?

blair.bethwaite at gmail.com blair.bethwaite at gmail.com
Sun May 7 23:58:33 EDT 2006


John Salerno wrote:
> Ugh, sorry about another post, but let me clarify: In these utility
> functions, I need to refer to an attribute of an instance, but these
> functions will be called from another method in the class, not from the
> instance itself. Is this even possible, or would 'self' have no meaning
> when used this way?

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.

If you're calling something in a class method then there must be an
instance of that class, instantiated as an object, in order to make the
call in the first place.

'self' does have meaning inside a class, you use it when you want to
call another method within the same class.  Python can then fill in the
self reference in the arguments to the callee for you as it does when
you call a method from outside of the class by qualifying with the
instance name.
inside class A:
   self.blah(args)
outside class A:
   a_A = A()
   a_A.blah(args)

Cheers,
-B
(Hope I've got this one right)




More information about the Python-list mailing list