Python Forum
Class Problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Class Problem (/thread-22592.html)



Class Problem - scratchmyhead - Nov-19-2019

I am writing a python program exactly the way my course instructor has and when I try to run on my end, I get the following error: AttributeError: 'TagCloud' object has no attribute 'tags'

Below is the code:

class TagCloud:
    def __int__(self):
        self.tags = {}

    def add(self, tag):
        self.tags[tag] = self.tags.get(tag, 0) + 1

cloud = TagCloud()
cloud.add("Python")
cloud.add("Python")
cloud.add("Python")
print(cloud.tags)
What am I doing wrong?


RE: Class Problem - Larz60+ - Nov-19-2019

line 2 should be:
    def __init__(self):
missing the i in init


RE: Class Problem - scratchmyhead - Nov-19-2019

Thank you for pointing that out. I feel really stupid. I guess I really need to watch my typing.


RE: Class Problem - Larz60+ - Nov-19-2019

it happens to everyone from time to time