NameError question - def(self,master) - master not in namespace within class?

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Oct 9 18:50:21 CEST 2008


bieffe62 at gmail.com a écrit :
<OT>
bieffe, please, learn to snip irrelevant material...
</OT>
> On 9 Ott, 17:43, harijay <hari... at gmail.com> wrote:
(snip)
>> NameError: name 'master' is not defined"

(snip)

>> #File runner.py
>> #!/usr/bin/python
>> import master
>> import child
>>
>> if __name__=="__main__":
>>         print "RUNNING RUNNER"
>>         m = master.master("hj","oldhj")
>>         s = child.child(m)
(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"
(snip)
> 
> You need to have an import master in child.py too.

Nope. The 'child' class is passed a 'master' instance when instanciated. 
You got confused by the bad naming.

<OP>
The convention in Python is to name classes in CamelCase. Your classes 
should be named 'Master' and 'Child'.
</OP>



More information about the Python-list mailing list