Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attribute error: has no attribute 'completeKey' - Python [closed]

Tags:

python

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()
like image 514
user3164083 Avatar asked Mar 07 '14 22:03

user3164083


1 Answers

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()
like image 83
Javier Avatar answered Oct 06 '22 00:10

Javier