By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,446 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,446 IT Pros & Developers. It's quick & easy.

having a problem with an instance of a method.

P: n/a
I wanted to dig a little deeper understanding of Classes, Methods and
Instances. However I get this - ' AClassA instance has no attribute' as
an error when I call the method I am using as a learning tool.

Here's the code, from
class AClassA:

def __init__(self):
self.a = 0

def printit(self):
print "done from Class a"

class BClassB:

def __init__(self):
self.a = 0

def printit(self):
print "done from Class b"

Here is the call
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>from hammer import *
x = AClassA()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: AClassA instance has no attribute 'printit'
['__doc__', '__init__', '__module__']
I can see that AClassA has no method defined so the error makes sense.

But I can't figure out why 'def printit(self): is not included as a
component of the class AClassA. The syntax looks right.

Observations on what I am doing wrong?

Jul 14 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.