[Solved] importing module causes TypeError: module.__init__() takes at most 2 arguments (3 given)

Please don’t mark as duplicate, other similar questions did not solve my issue.

This is my setup


from actions import ListitAction, ViewAction

class ListitAction(object):

    def __init__(self):
        #some init behavior

    def build_uri():
        return "test.uri"

from actions import ListitAction

class ViewAction(ListitAction):

    def __init__(self, view_id):
        self.view_id = view_id

    def build_uri():
        return "test"


$ python3

The only error message I receive is:

Traceback (most recent call last):
  File "/home/jlevac/workspace/project/", line 11, in <module>
    from actions import ListitAction, ViewAction, CommentsAction
  File "/home/jlevac/workspace/project/actions/", line 3, in <module>
    class ViewAction(ListitAction):
TypeError: module.__init__() takes at most 2 arguments (3 given)

Even if I try for the python3 console, I received the same error message:

from actions import ViewAction

I am new to Python, but not new to programming. I’m assuming that my error messages have to do with the import statements, but based on the message I can’t really figure out what it means.

Solution #1:

Your imports are wrong, so you’re trying to inherit from the modules themselves, not the classes (of the same name) defined inside them.

from actions import ListitAction

in should be:

from actions.ListitAction import ListitAction

and similarly, all other uses should switch to explicit imports of from actions.XXX import XXX (thanks to the repetitive names), e.g. from actions import ListitAction, ViewAction must become two imports:

from actions.ListitAction import ListitAction
from actions.ViewAction import ViewAction

because the classes being imported come from different modules under the actions package.

Respondent: ShadowRanger

Solution #2:

You are passing self when you don’t need to, that’s all.
Edit: see MSeifert’s comment answer since I don’t want to steal content.

Respondent: Idos

Solution #3:

If your file is in the root directory of the project then you can directly write the file name and import.

For example, if filename is and class name is Parent, then you would write

from Parent1 import Parent

However, if your file is under any folder for example:

DemoFolder -> >    Parent
(Folder).       (File).      (Class name)

Then you would have to write:

from Test.Parent1 import Parent
Respondent: Divesh singh

Solution #4:

Creating classes and instance of variables

class Student:
    # Creating a Class Variables
    perc_Raise = 1.05

    # Creating a constructor or a special method to initialize values
    def __init__(self,firstName,lastName,marks):
        self.firstName = firstName
        self.lastName = lastName = firstName + "." + lastName +""
        self.marks = marks

    def fullName(self):
        return '{} {}'.format(self.firstName,self.lastName)

    def apply_raise(self):
        self.marks = int(self.marks * self.perc_Raise)

Creating a two instance variable for a Student class

std_1 = Student('Mahesh','Gatta',62)
std_2 = Student('Saran','D',63)








class Dumb(Student):
    perc_Raise = 1.10

    def __init__(self,firstName,lastName,marks,prog_lang):
        self.prog_lang = prog_lang

std_1 = Dumb('Suresh','B',51,'Python')



Respondent: Naga Mahesh Gatta

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy