Why am I getting this Error message

Steve Holden steve at holdenweb.com
Thu Jan 28 15:25:19 EST 2010


Ray Holt 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'
> 
Because you have indented the last three lines to make them a part of
the Circle definition. Generally four spaces makes a better indent, and
that kind of problem is then much more obvious.

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/




More information about the Python-list mailing list