[Tutor] Explain
Bob Gailer
ramrom@earthling.net
Mon Mar 3 17:03:01 2003
--=======1DAC5065=======
Content-Type: text/plain; x-avg-checked=avg-ok-408946F3; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
At 04:32 PM 3/3/2003 -0500, Pete Versteegen wrote:
>--------------------------
>#!/usr/bin/python
>class Single:
>
> def ___init___(self, maxmonths):
> self.size = []
> self.n = maxmonths
> for i in range(0, self.n):
> self.size.append = 0.0
>
>if __name__ == '__main__':
> unitsize = Single(20)
> unitsize.size[10] = 500.
> print unitsize.size
>
>-----------------------------
>Traceback (most recent call last):
> File "./Single.py", line 11, in ?
> unitsize = Single(20)
>TypeError: this constructor takes no arguments
Count the underscores around init. There should be 2 before and 2 after.
After you fix that you will get another exception:
self.size.append = 0.0
AttributeError: 'list' object attribute 'append' is read-only
Correct syntax is: self.size.append(0.0)
Bob Gailer
mailto:ramrom@earthling.net
303 442 2625
--=======1DAC5065=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-408946F3
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 2/25/2003
--=======1DAC5065=======--