[Tutor] Silly Object Namespace Questions

Curtis Larsen curtis.larsen@Covance.Com
Thu, 24 May 2001 11:20:31 -0500


<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


Doing a "dir(x)" produces  "['x']", and after running "self.doit()"
(which prints "Gotcha!"), "dir(x)" gives "['str', 'x']".  Okay, soooo:


1. What namespace(s) do "x", "a", "str", and "wumpus" respectively
belong to?

2. Why isn't "a" visible?  (I know it relates to #1.)

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

4. Is using "undeclared" variables such as "a" and "wumpus" the best
way to temporarily manipulate data within an object instance without
"publishing" that data for external use?  (For example, you can print
"wumpus", or do calculations on "a", but no one can get at them
externally.)

5. Is there anything "wrong" with defining "x" on it's own?  (I've
usually seen such defined in the parm list of "__init__".)

6. What function(s) can I use to see/list methods such as "doit" within
an instance?  ("vars()" and "dir()" don't do it.)



Thanks!
Curtis



-----------------------------------------------------
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.