[Tutor] Another Class question.

SA sarmstrong13@mac.com
Wed, 14 Aug 2002 20:58:36 -0500


On 8/14/02 6:24 PM, "Magnus Lycka" <magnus@thinkware.se> wrote:

> The first parameter to a method, conventionally called self, is
> the instance object. If x is an instance of Fud, x.extract() is
> just a short form of Fud.extract(x).
> 
> So if the value of "tags" is to live beyond the execution of
> the search method, you need "self.tags = r'''...", and to access
> it in extract you need "re.findall(self.tags ..."
> 
> A plain "tags" would be a local variable that is garbage collected
> as soon as i goes out of scope (end of method). Search.tags would
> not help. "Tags" need to be an attribute of the particular instance
> object, not the method.
> 
Ahah!(I hope)

Let me make sure I understand You here:

1. When you create the instance x = Fud(), any string I pass to x is run
through __init__ and then passed to def extract through self.text?

2. But def extract will do nothing for 2 reasons. One, start and end were
never passed to the Class? Two, even if they had been passed, data from the
function search is not passed to the function extract?

3. so by saying x = Fud(text) is the same as Fud(x, text) which is saying:
    class Fud:
        def __init__(x, text):
            x.text = text
    Is this correct? (Keep in mind I'm trying to make this as general as
    possible)

So what I would like to do then is pass the data into the class, let the
class do all of the work, and then return the modified data. At the same
time, to make the class work for the a more general situation, it would also
have to be able to pass data to just part of the class and return the
output.

Am I on the right track here now, because this is one of the more difficult
concepts to grasp for a newbie.

Thanks in Advance.

SA

-- 
"I can do everything on my Mac I used to on my PC. Plus a lot more ..."
-Me