Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 23rd, 2005, 8:23 PM   #1
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
Class Problem 'Instance has no such attribute'

class Hero:
    def He_Stats(self):
        self.Hero_stats = {'hp':[10,10,0,100],'attack':[7,0,100],'defense':[6,0,100], 'initiative':[2,0,100]}
        

class Enemy:
    def En_Stats(self):
        self.Enemy_stats = {'hp':[3,3],'attack':[3],'defense':[3],'initiative':[0]}

class Printer(Enemy, Hero):
    def printer(self):
        en_stats = self.En_stats
        he_stats = self.He_stats
        print en_stats
        print he_stats

x = Printer()
x.printer

This is the code of a small rpg battle system i started to code...
But when i try to run it, it give me the message, that the Printer instance has no He_stats and En_stats attribute...
I just cannot get, what is wrong with this code... Any Ideas would be helpful!!!
Thx a lot
Fred
Fred is offline   Reply With Quote
Old May 23rd, 2005, 8:47 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
It works for me... But the last line is quite pointless, I think you forgot the () after the printer.

Edit:

Then it that case you need to do:

class Hero:
    def He_Stats(self):
        return {'hp':[10,10,0,100],'attack':[7,0,100],'defense':[6,0,100], 'initiative':[2,0,100]}
        

class Enemy:
    def En_Stats(self):
        return {'hp':[3,3],'attack':[3],'defense':[3],'initiative':[0]}

class Printer(Enemy, Hero):
    def printer(self):
        en_stats = En.En_stats()
        he_stats = He.He_stats()
        print en_stats
        print he_stats

En = Enemy()
He = Hero()
x = Printer()
x.printer()

That should do it.

If they are all seperate classes, they all have to be declared.

Last edited by Sane; May 23rd, 2005 at 9:42 PM.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC