Classes and Functions - General Questions

Setash Setash at gmail.com
Wed Oct 18 15:42:22 EDT 2006


I've got a tiny bit of coding background, but its not the most
extensive.

That said, I'm trying to wrap my head around python and have a couple
questions with classes and functions.

Two notable questions:

1) Classes. How do you extend classes?

I know its as easy as:

class classname(a)
   do stuff


But where does the parent class need to lie? In the same file? Can it
lie in another .py file in the root directory? Can it simply be
accessed via an import statement or just plain jane?

To clarify, as it may be worded poorly:

Can my directory structure look like

..
/class1.py
/class2.py

And have class2 inherit class1 without any import statements, or need
it be imported first?
Or need class1 and class2 be both declared in the same .py file if
there is inheritance?

I think thats a bit more clear :)




2) Function overloading - is it possible?

Can I have the following code, or something which acts the same in
python?:


def function(a, b)
   do things

def function(a, b, c)
   do things only if I get a third argument


Any thoughts / comments / etc? Just trying to get a solid foundation of
python before going any further.
Thanks!




More information about the Python-list mailing list