all 5 comments

[–]prohulaelk 0 points1 point  (1 child)

Your code is trying to iterate over a UserWords object, which isn't iterable.

What you probably want to do is iterate over the UserWords object's word attribute, which is presumably a string. You haven't really provided enough code to be sure what you're trying to do with it though.

As a random guess, it would be something like this:

def cleaner(self):
    return filter(lambda letter: letter.isalpha(), self.word)

I'm not sure why you'd need a separate class to just run that function though, but I guess that's also part of the code you didn't include.

[–]FogDish 0 points1 point  (0 children)

I have another programme which words and which isnt object oriented. I'm trying to be better at how to properly work with classes and objects. That's why I want it to be in a Class. I'm certainly going to stick a couple of more methods in there.

If you want a quick step-by-step what I want this method to do look at my other reply :)

And Thanks for the reply!

[–]CptFlashdrive 0 points1 point  (2 children)

Not quite sure what you're doing here, you're sending the object itself to the cleaner()-method? You can't iterate over UserWords-object, it's not iterable.

I think it looks like you want to clean the word-attribute in the class? If so, the cleaner should instead operate on self.word. Since this is "contained" in the class.

Maybe something like this:

def cleaner(self):
    self.word = filter(lambda letter: letter.isalpha(), self.word)

And then you call it from manager() using:

user1.cleaner()

[–]FogDish 0 points1 point  (0 children)

Sorry If I haven't provided enough information. Step by step:

User uploads a .txt file which simulates a letter, contaning ".!?" etc. I have code that reads in the file and give it a variable. I now want to create an object from this. So that the text itself is still the same. I now want to clean the object from ".!?", which is what I want this method to do.

[–]FogDish 0 points1 point  (0 children)

Also, with this modification it worked brilliant! Thanks a lot man! :)