I am learning Python and classes and i encountered a challenge that i need help with.
When I try to pass data from one class method to another class method i run into an error that tells me it misses a positional argument
example:
class Student:
def __init__(self, name):
self.name = name
def pass_to_dl(self):
DataLayer.Datalayer.create_dict_entry(self.name)
class Datalayer:
def __init__(self):
self.dict = {}
def create_dict_entry(self, name):
new_name = {"name":name}
self.dict.update(new_name)
new_student = Student("some_name")
The error I get is:
TypeError: create_new_student() missing 1 required positional argument:
i assume it is because create_dict_entry expects two arguments and I am sending only one
now i can overcome this if i do two things
- make the create_dict_entry in DataLayer static
- move the dict outside of the DataLayer class but truthfully that does not seem like the right approach to me i think
i would love to hear your view on this matter
thnx
ps. i dont want student to inherit from DataLayer as i consider DataLayer a non related class that just holds data that i acquire form classes such as Student, Teacher etc