How to pass objects to a function?

Chris Tavares christophertavares at earthlink.net
Fri Nov 2 00:34:14 EST 2001


"Shankar" <SNeelakantan_C at zaplet.com> wrote in message
news:4a0341c8.0111011723.53246ecd at posting.google.com...
> I am a python newbie.
>
> How do I  pass a user defined object to a function?
>
> if I have something like
>
> def func(session, url):
>         ...
>         ....
>
> and session is supposed to be an object of httpsession class, how
> would the interpreter know about it? I suppose all arguments are
> treated as strings.
> so, if I invoke a method such as session.getreply() or something I
> would get an error. The httpsession class is expected to have derived
> classes too.
> (that should not matter to the problem in hand anyway).
>

Arguments are not treated as strings - they're passed as object references.

Just try it - you'll find that it just works. As long as the object you pass
actually has the methods you're calling, it'll work just fine.

> Also, if anybody has used the httplib.py module, can someone tell me
> how to do a request.redirect() if the replycode is 302.
>

Can't help here.

-Chris






More information about the Python-list mailing list