Newbie OOP question
Kevin T. Ryan
ktr73 at rcn.com
Mon Nov 17 22:58:24 EST 2003
Ed wrote:
> I'm trying to create an OOP script but havn't quite figured out to do it.
> Here's and example of what I'm trying to do.
>
> 1st file. DOG.py
>
> class DOG:
> def printName(self):
> print "DOG"
>
> 2nd file: runDog.py
>
> #!/usr/bin/python
> import sys
> from Commands import *
> x = Commands()
> a.printName()
>
>
> when I run runDog.py ./runDOG.py it keeps coming up with an AttributeError:
> class Commands has no attribute 'printName"
>
> What am I doing wrong?
>
> thanks!
> Ed
> When
>
>
>
First, in your runDog.py file, you have to import your DOG.py file.
From there, you need to instantiate a "DOG" object. e.g.:
import DOG
other code...
myDog = DOG.DOG()
myDog.printName()
Hopefully that helps :)
More information about the Python-list
mailing list