Python Console commands

23 views Asked by At
def do_create(self, arg):
        """Create a new instance of BaseModel, save it to JSON, and print its id"""
        arg_list = arg.split()
        if len(arg_list) == 0:
            print("** class name missing **")
        else:
            class_name = arg_list[1]
            if class_name not in self.classes:
                print("** class doesn't exist **")
            else:
                new_instance = globals()[class_name]()
                new_instance.save()
                print(new_instance.id)

Please I need explanation to the code above

After running the executable, then running command on the console I get error messages that my list is out of range the comman I mean is as follows create BaseModel.

Note: This is the part where we have some issues else: class_name = arg_list[1]

0

There are 0 answers