Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Class Problem
#1
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?
Quote
#2
line 2 should be:
    def __init__(self):
missing the i in init
Quote
#3
Thank you for pointing that out. I feel really stupid. I guess I really need to watch my typing.
Quote
#4
it happens to everyone from time to time
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  problem with class method AmirAB 3 404 Feb-13-2019, 01:51 AM
Last Post: AmirAB
  A problem with child class Truman 2 641 Jul-02-2018, 12:37 AM
Last Post: ichabod801
  problem with simple class code diegoraffo 5 1,109 Jan-27-2018, 02:31 AM
Last Post: ka06059

Forum Jump:


Users browsing this thread: 1 Guest(s)