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'
Asked By: marlon

||

Answers:

Because

def __int__(self):

is misspelled – you don’t see "Initialized …" printed either, do you?

def __init__(self):

is the correct spelling.

Answered By: AKX
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.