[Tutor] Re: Newbie OOP Question. (diff between function, modu le and class)

alan.gauld@bt.com alan.gauld@bt.com
Mon, 10 Jun 2002 22:54:25 +0100


> So the "def __init__" is a function in the class and is assigning the
> variables x and y as attributes of the class, correct? 

Correct, and is a special magic method that Python calls 
when you create an instance of the class.

> variables x and y supplied outside of the class 

When you instantiate it you pass the values in:

x,y = 7,8
pt = Point(3,4)
pt2 = Point(x,y)

Creates two instances of Point. One with x,y set to 3,4 the 
other set to 7,8

> A module is more or less, in very general terms, a package of 
> classes and/or functions that are then imported into the 
> __main__ program, correct?

Yes altho they could be imported into another module too.

> these terms need better definitions for newbies 

That's a large part of what my web tutor tries to do!

> what is a namespace? Is that analagous to pwd of the program? 

No. Its to do with the visibility of a name within a program.
Its explained in the 'Whats in a Name?' topic on my web site.

> understandable by people with programming experience. I kind of need a
> "layman's" terms tutorial because I'm so new to programming.

Thats exactly what my tutor is for, especially useful to you 
might be the 'namespaces', 'modules and functions' and OOP topics.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld