[Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs

D-Man dsh8290@rit.edu
Tue, 6 Mar 2001 09:43:09 -0500


If I was able to follow the discussion properly, it seems as if Alan
gave rather good explanations of the issues at hand.  I adjusted the
indentation to show where Alan was responding to the original
questions.


On Tue, Mar 06, 2001 at 10:06:02AM +0000, alan.gauld@bt.com wrote:
| 
|    I am unsure, as to whether your answer really answers my question.  It
|    depends upon how Python was designed.
|    
| Yes and I admit I'm only passing on my understanding which is not
| intimate with the internals but based on reading books and news articles...

Same here.

|    Is there any way that one can access the amount of RAM being used?  In
|    this way one could do the import foo and the from foo import * and see
|    the relative amounts of Ram used.

Sure, use a profiler and get into the internals of the interpreter.
This will probably (almost certainly) require a knowledge of C and a
desire to see how it works ;-).

Someone asked this on c.l.py a little while back.  I don't remember
the outcome, but it should be in the archives.

| Since in both cases the module must be run I suspect there'd be no
| difference.

I think there is a difference, but that difference is insignificant.

| The only difference is in which names Python stores in its top level
| dictionary

This is why I think there is a difference.  Instead of having a single
reference in foo.__dict__ to the function/class/whatever there is a
reference in foo.__dict__ and this.__dict__ (if I may borrow the name
"this" from C++/Java).  There will be double the number of references,
but a reference is little more that 4 bytes (as I said before,
whatever space 'struct PyObject' requires) so the memory usage is
insignificant.  Though I suppose it may only be a PyObject* in which
case it is just a duplicate pointer without the other overhead of a
PyObject.  To be certain about this, one would most likely need to
peruse the C implementation a bit.

| (python names are all in dictionaries which is why the dir()
| function works as it does...) Because from foo import xxx only puts
| xxx into the dictionary anything else in foo's naming dictionary is
| not seen since foo itself is not seen.
|    
|    
|    I would take your word for it, but I would like to know how Python
|    works.
|    
| As I say I'm not the expert there, wait for Tim Peters or Remco or
| maybe Guido himself to answer that one :-)

Same here.  I also haven't looked at the C (or Java) implementation at
all and have only briefly seen snippets of the C API for extending the
interpreter.

| Maybe a real guru could chip in here and tell us how it really
| works?  cue Alex, Tim P, Remco et al?

As Remco said, the Reference Manual is the real authority on the
subject (aside from Guido or the Timbot of course).

-D