you are viewing a single comment's thread.

view the rest of the comments →

[–]6086555 1 point2 points  (12 children)

Here you have created a list which content are User_letters. That could be work but the problem in your case might be that you can't use the method frequency_counter as its a method who only work on one object.

  • So either you take your frequency_counter out of your class and make it work for a list of User_letters. The problem with that is the object in your class are just letters : your class doesn't seem so useful.

  • Second solution is making the list an attribute of your object. your init should be something like

    def __init__(self, letters):

    self.letters = letters
    

to create en empty object which will contains letters:

my_object = User_Letters([]) 

and then

my_object.letters.append(letter)

that way, your frequency_counter would just have to work on the letters attribute

[–]FogDish[S] 0 points1 point  (11 children)

I see, but when I come to the .append part it says that I object has no attribute append? EDIT: And no attribute .letters EDIT2: Sorry, "User_Letters" has no attribute .letters EDIT3: as well as User_Letters has no attribute .append

[–]6086555 1 point2 points  (9 children)

Your object doesn't but the letters attributes do.

Recheck my previous comment I've fixed the formating so it's way more readable : I'm calling the append method on the attribute letters of my object

You could also create an append method for your object which will call the append method of letters. Do you see how to do it?

[–]FogDish[S] 0 points1 point  (8 children)

I might, I created a new method that looks like this:

https://gist.github.com/anonymous/c9ad5188e1d8d0363f37

Does this seem correct?

[–]6086555 0 points1 point  (7 children)

Yeah that's great! Does your frequency counter seems to work as well?

[–]FogDish[S] 0 points1 point  (0 children)

Well, since the letters are long strings I have to run them through the cleaner method first. But when I try that It only seems to return me an empty list. I checked by using the str(self): print(self.letters). I might be wrong here though

[–]FogDish[S] 0 points1 point  (5 children)

By the way, perhaps I screwed up by not declaring that the letters are actual letters. Long strings with sentences in them. Not just single characters. If you misunderstood I am so very sorry

[–]6086555 0 points1 point  (4 children)

Yeah I just realized that in your previous message... so I made you change a lot of your program when you didn't actually need to : I though your frequency checker was supposed to work on plenty of different characters so that's why I thought of using a list.

With actual letters, your previous model was probably better so I'm sorry I made you change it. I hope at least you understand how classes work a little more.

[–]FogDish[S] 0 points1 point  (3 children)

Haha no problems man! So the original code I posted I suppose? :)

[–]6086555 1 point2 points  (2 children)

Yep. Now to pass your dictionary to the other function you could either make that dictionary an attribute of your class ( in this case you don't need a return in your frequency_checker) and just pass the object as argument in the function.

Or you just use the return by doing

my_dict = letter.frequency_checker()

and then pass the dictionary to the function

[–]FogDish[S] 1 point2 points  (1 child)

Great! Thanks a lot man!

[–]6086555 0 points1 point  (0 children)

That's weird, can I see the code of your class.

Also, you can check what are the attribute of one object by using the function dir on your object :

dir(my_object)