newbie lists and code examples for OOP.

Sheila King usenet at thinkspot.net
Fri Mar 1 08:04:44 EST 2002


On Fri, 01 Mar 2002 09:34:03 -0000, "skoria" <shomon at softhome.net> wrote in
comp.lang.python in article
<mailman.1014975303.15829.python-list at python.org>:

> 
> I'm trying to write a class where one function calls a method in the
> same class. Right now I'm doing this with trial and error, and I don't
> really understand where I need to put parentheses, use (self), etc. I
> can't find any "functional" examples of object oriented programming on
> any online tutorials, or any simple programs already written that can
> be used as a good tool to figure out how to call functions within
> classes in python, when to use self.* what internal functions (like
> __init__) can be used for. Lots of theory on this, but no functional
> examples.

For one thing:
A beginner's forum would be the Tutor mailing list:
http://mail.python.org/mailman/listinfo/tutor

A good reference I would recommend for the type of stuff you are asking
about:
Core Python Programming by Wesley Chun.

When to use self:

Do you want the method to be called in the following way:
object.method()

where the method is always called by an instance of the object?

Or would you like to be able to call it like this:

method()

without having to necessarily have an object to use that method?

if the former, use "self". If the latter, don't use "self".

Hope this answers some of your questions. Join the Tutor list and ask some
more. You will get some good answers.

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_




More information about the Python-list mailing list