[Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs
alan.gauld@bt.com
alan.gauld@bt.com
Tue, 6 Mar 2001 10:06:02 -0000
------_=_NextPart_001_01C0A625.0CBB34D0
Content-type: text/plain; charset="iso-8859-1"
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...
The fact that running bar.py produces 'hello from foo' in it does not make
it certain that a pointer is not used and that Python simply follows the
pointer to foo.py and puts it in.
True, but it does show that foo gets executed not just set up a pointer.
In fact if you think about how Python uses names/variabnles/references it
might make more sense. Python creates a new variable name when an assignment
occurs, thus:
baz = []
creates a new name baz pointing at an empty list.
For modules assignment is not appropriate so wwe use import as a mechanism
for
creating names thus:
import foo
creates a new name foo
But it also gives indirect access to all the names in foo. But those names
won't
exist in Python until their definitions(class, def or assignment statements)
have
been executed thus for the foo namespace to made available in Python the
module
*must* be executed on import (it could be executed on the first reference to
a foo
name but that's a minor nitpick, either way the entire module must be
executed
to create the names within it.)
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.
Since in both cases the module must be run I suspect there'd be no
difference.
The only difference is in which names Python stores in its top level
dictionary
(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 :-)
You wrote: Nope thats simply controlling the namespace not instantiating the
function.
I do not understand this, can you expand on it a bit?
See above...
T hen, are you saying that writing 'import foo' is not creating a pointer
to the file?
Not as such, its creating a name entry in a dictionary, slightly different.
That name entry in turn is, I believe a pointer to another dictionary of
names for the foo module, not the file foo.py.
Maybe a real guru could chip in here and tell us how it really works?
cue Alex, Tim P, Remco et al?
Alan G
------_=_NextPart_001_01C0A625.0CBB34D0
Content-type: text/html; charset="iso-8859-1"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.00.3013.2600" name=GENERATOR></HEAD>
<BODY bottomMargin=0 leftMargin=3 rightMargin=3 topMargin=0>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV>I am unsure, as to whether your answer really answers my question.
It depends upon how Python was designed.<SPAN class=700034509-06032001><FONT
color=#0000ff face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Yes
and I admit I'm only passing on my understanding which is not intimate with
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>the
internals but based on reading books and news articles...</SPAN></FONT></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV><SPAN class=700034509-06032001> </SPAN> The fact that running bar.py
produces 'hello from foo' in it does not make it certain that a pointer is not
used and that Python simply follows the pointer to foo.py and puts it in.<SPAN
class=700034509-06032001><FONT color=#0000ff face=Arial
size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>True,
but it does show that foo gets executed not just set up a
pointer.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>In
fact if you think about how Python uses names/variabnles/references it might
make more sense. </SPAN></FONT><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001>Python creates a new variable name when an assignment
occurs, thus:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>baz =
[]</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001>creates a new name baz pointing at an empty
list.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>For
modules assignment is not appropriate so wwe use import as a mechanism for
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001>creating names thus:</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>import
foo</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001>creates a new name foo</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>But it
also gives indirect access to all the names in foo. But those names won't
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>exist
in Python until their definitions(class, def or assignment statements) have
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>been
executed thus for the foo namespace to made available in Python the module
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>*must*
be executed on import (it could be executed on the first reference to a foo
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>name
but that's a minor nitpick, either way the entire module must be executed
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>to
create the names within it.)</SPAN></FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV>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. <SPAN
class=700034509-06032001><FONT color=#0000ff face=Arial
size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Since
in both cases the module must be run I suspect there'd be no difference.
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>The
only difference is in which names Python stores in its top level
dictionary</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001>(python names are all in dictionaries which is why the
dir() function works as </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>it
does...) Because from foo import xxx only puts xxx into the dictionary anything
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>else
in foo's naming dictionary is not seen since foo itself is not
seen.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV>I would take your word for it, but I would like to know how Python
works. <SPAN class=700034509-06032001><FONT color=#0000ff
face=Arial size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>As I
say I'm not the expert there, wait for Tim Peters or Remco or maybe Guido
himself </SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>to
answer that one :-)</SPAN></FONT></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV>You wrote: <FONT color=#0000ff face=Arial size=2><SPAN
class=310173617-05032001>Nope thats simply controlling the namespace not
instantiating the function. </SPAN></FONT></DIV>
<DIV> </DIV>
<DIV>I do not understand this, can you expand on it a bit? <SPAN
class=700034509-06032001><FONT color=#0000ff face=Arial
size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>See
above...</SPAN></FONT></DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
<DIV><SPAN class=700034509-06032001><FONT color=#0000ff face=Arial
size=2> T </FONT></SPAN>hen, are you saying that writing 'import
foo' is not creating a pointer to the file? <SPAN
class=700034509-06032001><FONT color=#0000ff face=Arial
size=2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Not as
such, its creating a name entry in a dictionary, slightly
different.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>That
name entry in turn is, I believe a pointer to another dictionary of
</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>names
for the foo module, not the file foo.py.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Maybe
a real guru could chip in here and tell us how it really
works?</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>cue
Alex, Tim P, Remco et al?</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN
class=700034509-06032001></SPAN></FONT> </DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=700034509-06032001>Alan
G</SPAN></FONT></DIV></BODY></HTML>
------_=_NextPart_001_01C0A625.0CBB34D0--