0

When I try to create an instance of an object from a class that inherits from other class I keep getting this error

TypeError: super() takes at least 1 argument (0 given)

If I don't create any instances then it runs. Found this question where it suggested to check python version. From what I see in the terminal I have Python 3.8.1 . Even when I try just copy and use a code from this guide, it doesn't work and I get the same answer.

Here's the code:

class Developer(Employee):
    raise_amount = 1.10

    def __init__(self,first,last,pay,prog_lang):
        super().__init__(first,last,pay)
        self.prog_lang = prog_lang


emp_1 = Developer('Corey','Schafer',50000,'S')

But if I use

Employee.__init__(self,first,last,pay)

instead of super() it does work.

jamylak
  • 128,818
  • 30
  • 231
  • 230
bm1125
  • 223
  • 1
  • 10
  • 2
    are you (still) using python 2? – hiro protagonist Feb 19 '20 at 08:10
  • try `super(Developer,self).__init__()` – Shubham Shaswat Feb 19 '20 at 08:10
  • for python 3 and above follow this ruling: `super().__init__()` instead of passing in the child class and an instance into `super()` – de_classified Feb 19 '20 at 08:16
  • @hiroprotagonist no. installed 3.8.1. Tried `super(Developer,self).__init__()` but it doesn't work as well. Same for just using `super().__init__()` – bm1125 Feb 19 '20 at 08:21
  • Are you sure you are *executing* this with python 3? Can you please show the entire traceback? – MisterMiyagi Feb 19 '20 at 08:22
  • 1
    are sure that you are really running this python interpreter? what if you put `import sys; print(sys.version)` at the beginning of your code? – hiro protagonist Feb 19 '20 at 08:22
  • @hiroprotagonist well you are correct `2.7.16 (default, Dec 3 2019, 07:02:07) ` ... So why when I type in the terminal `python --version` it returns 3.8.1 ? – bm1125 Feb 19 '20 at 08:27
  • 1
    that depends on your operating system and your setup. and how you start the python script you are writing (e.g. on linux: does your file start with sth like `#!/usr/bin/env python3`)? this may be worth a fresh question... – hiro protagonist Feb 19 '20 at 08:59
  • I just use sublime text. I tried doing alias `python. = python3` but it doesn't seem to help. I'll try to look for more solutions and if not i'll post new question. – bm1125 Feb 19 '20 at 09:06

0 Answers0