Why isn't the object attribute available?
Question:
class Test:
def __int__(self):
self.name = 'test'
print('Initialized ...')
if __name__ == '__main__':
test = Test()
print(test.name)
When I run it, it gives this error messageļ¼
AttributeError: 'Test' object has no attribute 'name'
Answers:
Because
def __int__(self):
is misspelled – you don’t see "Initialized …" printed either, do you?
def __init__(self):
is the correct spelling.
class Test:
def __int__(self):
self.name = 'test'
print('Initialized ...')
if __name__ == '__main__':
test = Test()
print(test.name)
When I run it, it gives this error messageļ¼
AttributeError: 'Test' object has no attribute 'name'
Because
def __int__(self):
is misspelled – you don’t see "Initialized …" printed either, do you?
def __init__(self):
is the correct spelling.