[Tutor] Silly Object Namespace Questions

Curtis Larsen curtis.larsen@Covance.Com
Fri, 25 May 2001 09:06:47 -0500


>>> "Sean 'Shaleh' Perry" <shaleh@valinux.com> 05/24/2001 11:41:35 AM
>>>

<snip>

> On 24-May-2001 Curtis Larsen wrote:
>> <Sigh> OK I'm still trying to wrap my head around class
namespace(s),
>> and I know this is gonna sound dumb, (BUT) I have a few questions
about
>> the following example:
>> 
>> class object1:
>>    def __init__(self):
>>       a = 10
>>       self.x = 1
>>    def doit(self):
>>       self.str = "This is a string"
>>       wumpus = "Gotcha!"
>>       print wumpus

<snip again>

>> 3. Although (I believe) "x" and "str" are "safe" from modification,
>> would another instance of "object1" change the value of "a" or
>> "wumpus"?

> yes, but not for why you are thinking.  Each object's doit() will
create a new
> variable called 'wumpus' when called.  This variable lives for as
long as it
> takes for doit() to execute, then it goes away.

Thanks (to everyone) -- that makes it all much more understandable. 
One thing I'm still missing though, is whether or not different
instances of the above example class will overwrite the "a" or "wumpus"
variables.  In other words, is the namespace for both those variables
shared amongst the different instances, and will one instance (possibly)
changing the the value of, say, "a" mean that another instance will also
perceive the change?

If it helps, what I'm looking for is the best way to use "temporary"
calculation ("working") variables within a class (or methods of that
class) without callers seeing those variables (unlike the "x" variable
above).  "a" and "wumpus" appear to be good examples of doing this very
thing, but if different instance will step on each others values for
them, it would be... ummmm... "bad".

One other question: If you have an import statement within a method or
function, how often does the import actually occur?  Once upon
instantiation?  Every time the function/method is called?  Only once
ever? (Wow!  Not *that* would be a nifty pre-parser!)


Thanks!
Curtis


PS: Thanks very much also for the example code on listing methods --
I'll use it!



-----------------------------------------------------
Confidentiality Notice: This e-mail transmission 
may contain confidential or legally privileged 
information that is intended only for the individual 
or entity named in the e-mail address. If you are not 
the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or reliance 
upon the contents of this e-mail is strictly prohibited. 

If you have received this e-mail transmission in error, 
please reply to the sender, so that we can arrange 
for proper delivery, and then please delete the message 
from your inbox. Thank you.