0

I want to insert an object into a list and I gives me an error saying:

    Archive.insertdoc(d)
TypeError: insertdoc() missing 1 required positional argument: 'd'

This is in my Main module:

doc = Document(name, author, file)
Archive.insertdoc(doc)

Archive module:

def __init__(self):
    self.listdoc = []

def insertdoc(self, d):
    self.listdoc.append(d)
0

2 Answers 2

2

You need to create an instance of the Archive class; you are accessing the unbound method instead.

This should work:

archive = Archive()

doc = Document(name, author, file)
archive.insertdoc(doc)

This assumes you have:

class Archive():
    def __init__(self):
        self.listdoc = []

    def insertdoc(self, d):
        self.listdoc.append(d)

If you put two functions at module level instead, you cannot have a self reference in a function and have it bind to the module; functions are not bound to modules.

If your archive is supposed to be a global to your application, create a single instance of the Archive class in the module instead, and use that one instance only.

Sign up to request clarification or add additional context in comments.

Comments

2

It looks like Archive.insertdoc is an instance method of the class Archive. Meaning, it must be invoked on an instance of Archive:

doc = Document(name, author, file)
archive = Archive()     # Make an instance of class Archive
archive.insertdoc(doc)  # Invoke the insertdoc method of that instance

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.