Why am I getting this Error message
Chris Rebert
clp2 at rebertia.com
Thu Jan 28 15:16:14 EST 2010
On Thu, Jan 28, 2010 at 11:57 AM, Ray Holt <mrholtsr at sbcglobal.net> wrote:
> Why am I getting the following error message. Area has been declared as an
> attribute of Circle. Thanks, Ray
>
> class Circle:
> def __init__(self):
> self.radius = 1
> def area(self):
> return self.radius * self.radius * 3.14159
> c = Circle()
> c.radius = 3
> print c.area()
>
> Traceback (most recent call last):
> File "<pyshell#9>", line 1, in <module>
> class Circle:
> File "<pyshell#9>", line 8, in Circle
> print c.area()
> AttributeError: Circle instance has no attribute 'area'
Unable to reproduce:
Python 2.6.4 (r264:75706, Dec 20 2009, 15:52:35)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
>>> class Circle:
... def __init__(self):
... self.radius = 1
... def area(self):
... return self.radius * self.radius * 3.14159
...
>>> c = Circle()
>>> c.radius = 3
>>> print c.area()
28.27431
Cheers,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list