NameError question - def(self, master) - master not in namespace within class?
Jerry Hill
malaclypse2 at gmail.com
Thu Oct 9 12:07:10 EDT 2008
On Thu, Oct 9, 2008 at 11:43 AM, harijay <harijay at gmail.com> wrote:
> Hi I am new to writing module and object oriented python code. I am
> trying to understand namespaces and classes in python.
>
> I have the following test case given in three files runner , master
> and child. I am getting an error within child where in one line it
> understands variable master.name and in the next line it gives a
> NameError as given here
>
<snip>
> #File child.py
> class child():
> def __init__(self,master):
> print "Master name is %s" % master.name
> print "Now seeting master name to setnameinchild in child.py "
> tmp = master.trash
> master.trash = master.name
> master.name = "setnameinchild"
> print "Reset name now from %s to %s , oldname %s is saved in
> mastertrash" % (master.trash, master.name , master.trash)
The last line (starting with print), is not indented to the correct
level. Assuming it's supposed to be part of the child class's
__init__ method, it needs to line up with the rest of that method.
--
Jerry
More information about the Python-list
mailing list