[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>>Message: 15
<DIV></DIV>>Date: Wed, 14 Mar 2001 15:22:09 +1100
<DIV></DIV>>From: Margaret Brierton <MARGARET@RETRIEVER.COM.AU>
<DIV></DIV>>Organization: Retriever Communications
<DIV></DIV>>To: tutor@python.org
<DIV></DIV>>Subject: [Tutor] constructors
<DIV></DIV>>
<DIV></DIV>>Hi I'm another new one to python.
<DIV></DIV>>
<DIV></DIV>>I seem to be having a problem with class constructors. My program is
<DIV></DIV>>tiny and consists of the following code:
<DIV></DIV>>
<DIV></DIV>>#! /usr/bin/env python
<DIV></DIV>>
<DIV></DIV>>class ConnectInfo:
<DIV></DIV>> def _init_(self, accname):
<DIV></DIV>> self.accname=accname
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>def main():
<DIV></DIV>> connect = ConnectInfo("me")
<DIV></DIV>> print connect.accname
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>main()
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>when i run the above program i get the following error message:
<DIV></DIV>>
<DIV></DIV>>Traceback (innermost last):
<DIV></DIV>> File "test.sh", line 15, in ?
<DIV></DIV>> main()
<DIV></DIV>> File "test.sh", line 11, in main
<DIV></DIV>> connect = ConnectInfo("me")
<DIV></DIV>
<DIV> </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> </DIV>
<DIV>class ConnectInfo:
<DIV></DIV> def __init__(self, accname):
<DIV></DIV> self.accname=accname </DIV>
<DIV> </DIV>
<DIV>See if that works!</DIV>
<DIV> </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>