Question on class member in python
Alex Martelli
aleaxit at yahoo.com
Tue Oct 18 07:18:54 EDT 2005
Johnny Lee <johnnyandfiona at hotmail.com> wrote:
> Alex Martelli ???
Now that's a peculiar question...
> > Johnny Lee <johnnyandfiona at hotmail.com> wrote:
> >
> > > But I still wonder what's the difference between the A().getMember and
> > > A().member besides the style
> >
> > Without parentheses after it, getMember is a method. The difference
> > between a method object and an integer object (which is what member
> > itself is in your example) are many indeed, so your question is very
> > strange. You cannot call an integer, you cannot divide methods, etc.
> >
> >
> > Alex
>
> Sorry, I didn't express myself clear to you. I mean:
> b = A().getMember()
> c = A().member
> what's the difference between b and c? If they are the same, what's the
> difference in the two way to get the value besides the style.
If getMember's body is nothing but a 'return self.member', then there is
no difference -- 'assert b is c'.
What is the difference between:
x = 2
and
y = 2+2-2*2/2
??? Answer: in terms of final results, no difference. On the other
hand, the second approach does a lot of obviously useless and intricate
computation, so it's a sheer waste of time and effort.
Exactly the same answer applies to your question -- obtaining the
.member attribute "indirectly", by calling a method that returns it,
does some obviously useless and moderately intricate computation, which
in some ways is a waste of (some) time and effort. That's all!
Alex
More information about the Python-list
mailing list