how to give an object as argument for a method

Geoff Gerrietts geoff at gerrietts.net
Tue Mar 5 18:28:07 EST 2002


Quoting Marco Herrn (herrn at gmx.net):
> Hello,
> 
> I am new to python and have a question how to achieve $subject.
> 
> I want something like the 'this' statement in java that gives you the
> current object. So when I call a method like f(this) I give the object
> that calls the method as argument.
> But how can I do this in python?
> I am using python 2.1.

Unless I'm grossly misreading your question, the answer is that python
more or less does that for you automatically.

    class Spam:
        def method(self):
            print "Look at me, I'm ", self

    eggs = Spam()
    eggs.method()

If you're looking for something more sophisticated than that, I think
you need to rephrase your question (or hold out for someone who
understands your problem better).

Thanks,
--G.

-- 
Geoff Gerrietts             "Punctuality is the virtue of the bored." 
<geoff at gerrietts net>                               --Evelyn Waugh




More information about the Python-list mailing list