Question on class member in python
Christophe
chris.cavalaria at free.fr
Tue Oct 18 07:06:20 EDT 2005
Johnny Lee a écrit :
> Alex Martelli 写道:
>
>
>>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.
>
Second form is better because it makes it easier to refactor.
Like, at first A had a direct access to the member member. But later you
want to control the access to it. So you change it into a property and
you don't need to change client code.
More information about the Python-list
mailing list