<br><br><div class="gmail_quote">On Mon, Feb 6, 2012 at 12:58 PM, Dave Angel <span dir="ltr"><<a href="mailto:d@davea.name">d@davea.name</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 02/06/2012 01:24 PM, Tonu Mikk wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now I get an error: NameError: global name 'self' is not define.<br>
<br>
Tonu<br>
<br>
<br>
</blockquote></div>
Put your remarks after the stuff you quote. You're top-posting, which makes the reply difficult to follow.<br>
<br>
Use copy/paste to describe an error message. You retyped the one above, and added a typo. Include the whole error, which includes the stack trace.<br>
<br>
If you had followed Nate's advice, you couldn't have gotten that error at all, so you'll also need to post the code that actually triggers the error.</blockquote><div><br></div><div>Let's try this one more time. I thought that I would try to make Alan's code work. Here is the version what I have now:</div>
<div><br></div><div><div>class Printer:</div><div> def __init__(self,number=0):</div><div> self.value = number</div><div> def sayIt(self):</div><div> print self.value</div><div><br></div><div>class MyApp:</div><div>
def __init__(self, aPrinter = None):</div><div> if aPrinter == None: # if no object passed create one</div><div> aPrinter = Printer()</div><div> self.obj = aPrinter # assign object</div><div> def doIt():</div>
<div> self.obj.sayIt() # use object</div><div><br></div><div>def test():</div><div> p = Printer(42)</div><div> a1 = MyApp()</div><div> a2 = MyApp(p) # pass p object into a2</div><div> a1.doIt(self) # prints default value = 0</div>
<div> a2.doIt(self) # prints 42, the value of p</div><div><br></div><div>test()</div></div><div><br></div><div>When I run it, I get an error:</div><div><div>Traceback (most recent call last):</div><div> File "alan_class.py", line 22, in <module></div>
<div> test()</div><div> File "alan_class.py", line 19, in test</div><div> a1.doIt(self) # prints default value = 0</div><div>NameError: global name 'self' is not defined</div></div><div><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
<br>
<br>
<br>
-- <br>
<br>
DaveA<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"><div>Tonu Mikk</div><div>Disability Services, Office for Equity and Diversity</div>
<div>612 625-3307</div><div><a href="mailto:tmikk@umn.edu" target="_blank">tmikk@umn.edu</a></div></span><br>