[Tutor] inquiry

Alan Gauld alan.gauld at yahoo.co.uk
Sat Nov 26 06:41:22 EST 2016


On 26/11/16 04:59, zxjhust1 wrote:
> Dear tutors:
>        I have some questions about memory mechanism of python. 

Depending on the level of detail you need this might be more appropriate
to the general Python list. Implementation details
are usually a bit too advanced for most readers of tutor.

However if all you want are the practical details of how to
utilise the memory model this list is fine.

> Do the elements of the parent go into the namespace of 
> the subclass when we define subclass?
>  
> As far as I'm concerned, they do go into the namespace 
> of the subclass. Because when we use dir(),
> we can see all the elements. 

> But there is only one 'update' name. 

I'm not sure what you mean by that?
Where are you getting 'update' from?

> I think the function of the subclass override the parent's.

Yes that's the expected behaviour.

>   In this situation , when we instantiate the subclass, 
> we just need one argument, that is to say,
> the parent's update function do the work.

I think you need to post some code because what you are
talking about sounds like its related to a specific
example which we can't see...


> According to my understanding, as there is no 'super' key word, 

There is a form of super in Python although it works
differently in v2 and v3. Which python version are you using?
And both cases work differently to Java and Smalltalk.

> Another quesion is about the meaning of the private variables. 

Again you need to be more specific. Private attributes in Python
are a bit of a bodge, more of a convention than a guarantee.

> What condition shall we use them? In other word, I wanna 
> know the purpose of introducing the private variables.

Are you familiar with OOP in other languages?
That will affect how we answer that question...

I have to run, hopefully someone else will picjk this
up in more detail.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list