F
F
Fallerwood2021-09-29 09:12:49
Python
Fallerwood, 2021-09-29 09:12:49

Why doesn't it exist in the attribute call?

class Client:
  def __init__(self, client_id, name, phone, location, time):
    self.client_id = client_id
    self.name = name
    self.phone = phone
    self.location = location
    self.time = time

Conclusion when contacted:
AttributeError: type object 'Client' has no attribute 'client_id'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Golovanenko, 2021-09-29
@Fallerwood

It looks like you are trying to get an attribute not of an object, but of a class. First create an object of the Client class, the __init__ constructor will run, which will create the required attribute on the new object:

class Client:
  def __init__(self, client_id, name, phone, location, time):
    self.client_id = client_id
    self.name = name
    self.phone = phone
    self.location = location
    self.time = time


my_client = Client(123456, "Vasya", "123456", "Lviv", 1234567890)
print(my_client.client_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question