Python Object-Oriented Python Inheritance Super-Duper!

Antonia Bruno
Antonia Bruno
4,283 Points

Python inheritance, why is it throwing a SyntaxError when I run the program? [Solved]

import random

class Character:
    def __init__(self, name, **kwargs):
        self.name = name
        for key, value in kwargs.items():
            setattr(self, key, value)


class Thief(Character):
    sneaky = True

    def __init__(self, name, sneaky=True, **kwargs):
        super().__init__(name, **kwargs)
        self.sneaky = sneaky

    def pickpocket(self):
        return self.sneaky and bool(random.randint(0, 1))  

    def hide(self, light_level):
        return self.sneaky and light_level < 10    
source /Users/antonia/anaconda3/bin/activate
conda activate base
(base) antonias-MacBook-Pro:objectO antonia$ source /Users/antonia/anaconda3/bin/activate
(base) antonias-MacBook-Pro:objectO antonia$ conda activate base
(base) antonias-MacBook-Pro:objectO antonia$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from character import Thief
>>> antonia = ("Antonia", sneaky=False, clever=True)
  File "<stdin>", line 1
    antonia = ("Antonia", sneaky=False, clever=True)
                                ^
SyntaxError: invalid syntax
>>>

1 Answer

Antonia Bruno
Antonia Bruno
4,283 Points

Actually fixed that problem forgot to add Theif before defined the attributes. But now it's giving me this error

SyntaxError: invalid syntax
>>> antonia = Thief("Antonia", sneaky=False, clever=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "character.py", line 14, in __init__
    super().__init__(name, **kwargs)
TypeError: super() takes at least 1 argument (0 given)
>>>