# animal.py
class Animal:
def __init__(self):
self.action = {'feed':feed_pet}
def do_action(self, a):
action[a]()
def feed_pet(self):
print('Gives some food')
# main.py
from animal import *
my_pet = Animal()
my_pet.do_action('feed')
I am tyring to make game, but this code gave me the following error:
Traceback (most recent call last):
File "so.py", line 3, in <module>
my_pet = Animal()
File "/home/wdwickar/pyside/animal.py", line 4, in __init__
self.action = {'feed':feed_pet}
NameError: name 'feed_pet' is not defined
Is there no forward declaration in Python like C ?