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,
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
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
[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
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
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
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
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
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
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
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
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
[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
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
[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
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
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
[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
[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
> 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
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
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
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
23 matches
Mail list logo