I created an enemy class that reads data from a file to get its instance variables. The file is written to different arrays for the different types of enemies. They work fine. When I write them to the object then try to print them I get the error:
AttributeError: 'NoneType' object has no attribute 'type'
If I don't print the 'type' attribute then it says:
AttributeError: 'NoneType' object has no attribute 'health'
The class is:
def Enemy(object):
def __init__(self, TypeStats):
self.type = TypeStats[0][0]
self.health = int(TypeStats[0][1])
self.strength = int(TypeStats[0][2])
self.dead = False
The code to write the array to the object and print the variables is:
Bandit = Enemy(BanditStats)
print Bandit.type, Bandit.health, Bandit.strength
The reason I write it as a 2D array is because when I write the data from the file to the array it creates an array:
BanditStats = [['Bandit', '80','7']]
I don't know why that happens is it easy to fix?