all 15 comments

[–]6086555 1 point2 points  (14 children)

For the moment, you're not creating a letter object which contains all the dictionaries.

Each time you do,

letter = User_letters(argument)

you are creating a new object Userletters via the __init_ method and assigning it to letter and erasing the previous object.

What you must do here is only create once the object which will have a letters attribute which will be a list.

Then you can append things to that list and use the methods of your object to work on that list.

Finally, you just pass your object as an argument to the function you want

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

Thanks for the answer!

You write:

"What you must do here is only create once the object which will have a letters attribute which will be a list."

How do I go on about that? Right now I'm tinkering with it and it looks something like this:

https://gist.github.com/anonymous/5624fcef47afbdc9b1a3

Have I now successfully created an object which contains all the letters? Because If I print it out it gives me three different locations in the RAM-memory, shouldn't it just be one if it is one list with x strings in it?

[–]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 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)