I get the following error when running this code:
Attribute error: DisplayWelcome has no attribute 'completeKey'
import controller.game_play
import cmd
class DisplayWelcome(cmd.Cmd):
"""Welcome user to game"""
def __init__(self):
self.do_greet()
prompt = 'ENTER'
intro = '\n'.join([' Welcome To ',
'...ZOMBIE IN MY POCKET...'])
def do_greet(self):
print (' Welcome To ')
print ("...ZOMBIE IN MY POCKET...")
def do_inform(self, line):
k = input('Enter a letter')
print (k)
def main():
d = DisplayWelcome()
#d.do_greet()
d.cmdloop()
s = controller.game_play.stuff()
if __name__ == '__main__':
main()
This is an easy one... ;-) You forgot to call the constructor of the parent class (cmd.Cmd). There the completekey attribute is automatically declared with a default value. That solves the problem!
import controller.game_play
import cmd
class DisplayWelcome(cmd.Cmd):
"""Welcome user to game"""
def __init__(self):
#### THIS IS THE LINE YOU FORGOT!!!!
super(DisplayWelcome, self).__init__()
# or cmd.Cmd.__init__(self)
self.do_greet()
prompt = 'ENTER'
intro = '\n'.join([' Welcome To ',
'...ZOMBIE IN MY POCKET...', ' Created by Ben Farquhar '])
def do_greet(self):
print (' Welcome To ')
print ("...ZOMBIE IN MY POCKET...")
print (" Created by Ben Farquhar ")
def do_inform(self, line):
k = input('Enter a letter')
print (k)
def main():
d = DisplayWelcome()
#d.do_greet()
d.cmdloop()
s = controller.game_play.stuff()
if __name__ == '__main__':
main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With