Hey, I have trying to build a large hierarchical tree of all sorts of creatures in Python by using class inheritance. However I seem to have been halted before I can even get anywhere.

I created my first base class:

class Creature(object):
    def __init__(self):
        self.hitPoints = 100
        self.legs = 1
        self.legHitPointsTotal = 3 * self.hitPoints / 10
        self.individualLegHP = self.legHitPointsTotal / self.legs
        self.isDead = bool(False)
        self.isMobile = bool(True)

        if self.hitPoints < 1:
            self.isDead = bool(True)

Then when I try to test this class through the derived class I get this error

Traceback (most recent call last):
File "/myHomeDirectory/NetBeansProjects/creatureLists/src/superTypes/insects/Insects.py", line 4, in <module>
from Creatures import Creature
File "/myHomeDirectory/NetBeansProjects/creatureLists/src/Creatures.py", line 6, in <module>
File "/myHomeDirectory/NetBeansProjects/creatureLists/src/Creatures.py", line 9, in Creature
NameError: name 'false' is not defined

In case it's important, here is the derived class as well:

class Insects(Creature):
    def __init__(self):
        Creature(Subclass, self).__init__()
        self.hitPoints = 80
        self.legs = 6

        if self.legHitPointsTotal == 0:
            self.isMobile = bool(False)

I don't even need to try and do anything more that simply running the derived class and it gives me that error. Am I mistaken or is there no 'false' in either class? Please help.

Recommended Answers

All 2 Replies

File "/myHomeDirectory/NetBeansProjects/creatureLists/src/Creatures.py", line 6, in <module>
File "/myHomeDirectory/NetBeansProjects/creatureLists/src/Creatures.py", line 9, in Creature
NameError: name 'false' is not defined

This says that line 6 in "Creatures.py" is calling line 9 = false not defined. Nothing like that in the code you posted. Are you running from another directory that also contains a "Creatures.py" program?

I looked into my src directory... and there were two 'additional' Creatures.pyc lying around. I removed those, and now it can't find the module at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.