Re: utility functions within a class?

2006-05-09 Thread John Salerno
bruno at modulix wrote: >> but these >> functions will be called from another method in the class, not from the >> instance itself. > > yes, they will: > > class Parrot(object): >def _func1(self, whatever): > print whatever > > def talk(self): > self._func1('vroom') > HTH. yes,

Re: utility functions within a class?

2006-05-09 Thread John Salerno
bruno at modulix wrote: > The convention for 'protected' > attributes (which should really be named 'implementation attributes') FWIW, I agree. When I hear 'protected attribute' I think of an attribute that can only be used within its class and subclasses of it. -- http://mail.python.org/mailm

Re: utility functions within a class?

2006-05-09 Thread bruno at modulix
John Salerno wrote: > John Salerno wrote: > >> [EMAIL PROTECTED] wrote: >> >>> John Salerno wrote: >>> 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 th

Re: utility functions within a class?

2006-05-09 Thread bruno at modulix
[EMAIL PROTECTED] wrote: > John Salerno wrote: > >>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. > > > Yep, so you want to encapsulate the fun

Re: utility functions within a class?

2006-05-09 Thread bruno at modulix
John Salerno wrote: > [EMAIL PROTECTED] 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 imp

Re: utility functions within a class?

2006-05-09 Thread bruno at modulix
John Salerno wrote: > John Salerno wrote: > >> [EMAIL PROTECTED] wrote: >> >>> Even if you don't end up referring to self or any instance >>> attributes within the method >> >> >> Hmm, follow-up: I *do* plan to refer to instance attributes inside >> these methods (self.something), but does that re

Re: utility functions within a class?

2006-05-08 Thread Scott David Daniels
John Salerno wrote: > Scott David Daniels wrote: >> John Salerno wrote: >>> ... But isn't there something about a single leading underscore >>> that doesn't import when you use from X import *? Or am I thinking of >>> something else? Is that also the double underscore? >> >> That has to do with m

Re: utility functions within a class?

2006-05-08 Thread John Salerno
Scott David Daniels wrote: > John Salerno wrote: >> Dennis Lee Bieber wrote: >>> ... Single underscores are a convention/signal to the programmer that >>> "this method/attribute" is considered "private" and should only be used >>> by other methods within the class that defined it. The language do

Re: utility functions within a class?

2006-05-08 Thread Scott David Daniels
John Salerno wrote: > Dennis Lee Bieber wrote: >> ... Single underscores are a convention/signal to the programmer that >> "this method/attribute" is considered "private" and should only be used >> by other methods within the class that defined it. The language does no >> enforcement of usage

Re: utility functions within a class?

2006-05-08 Thread John Salerno
Dennis Lee Bieber wrote: > tOn Mon, 08 May 2006 14:04:34 GMT, John Salerno > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > >> I tried the underscore method, but I was still able to call it as a >> regular instance method in the interpreter. Is that what's supposed to >> happ

Re: utility functions within a class?

2006-05-08 Thread Scott David Daniels
John Salerno wrote: > John Salerno wrote: >> [EMAIL PROTECTED] wrote: >>> John Salerno wrote: 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 it

Re: utility functions within a class?

2006-05-08 Thread John Salerno
John Salerno wrote: > [EMAIL PROTECTED] wrote: >> John Salerno wrote: >>> 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. >> >> Yep, so you wan

Re: utility functions within a class?

2006-05-08 Thread John Salerno
[EMAIL PROTECTED] wrote: > John Salerno wrote: >> 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. > > Yep, so you want to encapsulate the functi

Re: utility functions within a class?

2006-05-07 Thread blair . bethwaite
John Salerno wrote: > 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. Yep, so you want to encapsulate the functionality that those methods provide

Re: utility functions within a class?

2006-05-07 Thread John Salerno
[EMAIL PROTECTED] 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

Re: utility functions within a class?

2006-05-07 Thread blair . bethwaite
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 n

Re: utility functions within a class?

2006-05-07 Thread John Salerno
John Salerno wrote: > [EMAIL PROTECTED] wrote: > >> Even if you don't end up referring to self or any instance >> attributes within the method > > Hmm, follow-up: I *do* plan to refer to instance attributes inside these > methods (self.something), but does that require that they be instance > m

Re: utility functions within a class?

2006-05-07 Thread John Salerno
[EMAIL PROTECTED] wrote: > Even if you don't end up referring to self or any instance > attributes within the method Hmm, follow-up: I *do* plan to refer to instance attributes inside these methods (self.something), but does that require that they be instance methods, or can they still referenc

Re: utility functions within a class?

2006-05-07 Thread John Salerno
[EMAIL PROTECTED] wrote: > Even if you don't end up referring to self or any instance > attributes within the method, it's simpler to keep it as a normal > method. Thanks, that makes sense to me! So basically just create them as methods, and if I want a little 'privacy' I can lead with an unders

Re: utility functions within a class?

2006-05-07 Thread blair . bethwaite
> You do *NOT* want to put double-underscores before and after a method > name. That does not indicate a private method, it indicates a "magic > method" WHOOPS!! Sorry, I haven't touched python for a few months and just started working on a script this morning so was going to post my own questio

Re: utility functions within a class?

2006-05-07 Thread [EMAIL PROTECTED]
You do *NOT* want to put double-underscores before and after a method name. That does not indicate a private method, it indicates a "magic method" -- something that has special meaning to Python. Thus, you have special methods like __init__(), __len__(), __getattr__(), __setattr__(), etc; all of

Re: utility functions within a class?

2006-05-07 Thread blair . bethwaite
It sounds like all you want is some encapsulation, the following makes methods __head__ and __body__ "private" - the double underscores are important. I'd suggest reading the Object bits of the python tutorial also. class HTMLWrapper: def generate(self, ...): ... self.__head__(foo

utility functions within a class?

2006-05-07 Thread John Salerno
I might be missing something obvious here, but I decided to experiment with writing a program that involves a class, so I'm somewhat new to this in Python. Anyway, what is the best way to create a function (A) within a class that another function (B) can use? Function A is not something that an