[Tutor] Re: Tutor digest, Vol 1 #659 - 15 msgs

Britt Green britt_green@hotmail.com
Tue, 13 Mar 2001 23:13:06 -0800


<html><DIV></DIV>&gt;Message: 15 
<DIV></DIV>&gt;Date: Wed, 14 Mar 2001 15:22:09 +1100 
<DIV></DIV>&gt;From: Margaret Brierton <MARGARET@RETRIEVER.COM.AU>
<DIV></DIV>&gt;Organization: Retriever Communications 
<DIV></DIV>&gt;To: tutor@python.org 
<DIV></DIV>&gt;Subject: [Tutor] constructors 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Hi I'm another new one to python. 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;I seem to be having a problem with class constructors. My program is 
<DIV></DIV>&gt;tiny and consists of the following code: 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;#! /usr/bin/env python 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;class ConnectInfo: 
<DIV></DIV>&gt; def _init_(self, accname): 
<DIV></DIV>&gt; self.accname=accname 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;def main(): 
<DIV></DIV>&gt; connect = ConnectInfo("me") 
<DIV></DIV>&gt; print connect.accname 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;main() 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;when i run the above program i get the following error message: 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Traceback (innermost last): 
<DIV></DIV>&gt; File "test.sh", line 15, in ? 
<DIV></DIV>&gt; main() 
<DIV></DIV>&gt; File "test.sh", line 11, in main 
<DIV></DIV>&gt; connect = ConnectInfo("me") 
<DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV>Althought its hard to tell, I think you're not putting *two* underscore characters around the constructor. Try changing it to:</DIV>
<DIV>&nbsp;</DIV>
<DIV>class ConnectInfo: 
<DIV></DIV>&nbsp;&nbsp;&nbsp;  def __init__(self, accname): 
<DIV></DIV>&nbsp;&nbsp;&nbsp;  self.accname=accname </DIV>
<DIV>&nbsp;</DIV>
<DIV>See if that works!</DIV>
<DIV>&nbsp;</DIV>
<DIV>Britt</DIV><br clear=all><hr>Get your FREE download of MSN Explorer at <a href="http://explorer.msn.com">http://explorer.msn.com</a><br></p></html>