TypeError: dump() missing 1 required positional argument: 'fp' code example
Example 1: python missing 1 required positional argument:
def your_method(self, arg1, arg2):
'''
This kind of error happens when working with classes
When you create methods for a class, you must always pass self as the first argument
self designates the object in which it is called
'''
class Dog:
def __init__(self, color, age):
self.color = color
self.age = age
self.bark("Woof")
def bark(self, message):
print(message)
'''
This is a very simple example but it stays true for every class
You have to pass self as the first argument for each method
'''
Example 2: python missing 1 required positional argument:
"""
This might pop up if you're trying to use a class directly,
rather than instantiating it
"""
class MyClass:
def __init__(self, attr) -> None:
self.attr = attr
def get_attr (self):
self.attr
myclass = MyClass(1)
print (type(myclass))
print (myclass.get_attr())
myclass = MyClass
print (type(myclass))
print (myclass.get_attr())
print (type(MyClass))
print (MyClass.get_attr())