Classes and Functions - General Questions
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! -- http://mail.python.org/mailman/listinfo/python-list
Re: Classes and Functions - General Questions
> > > > And have class2 inherit class1 without any import statements, or need > > it be imported first? > > It needs to be imported first: > > class1.py: > > class Class1(object): > pass > > class2.py: > import class1 > > class Class2(class1.Class1): > pass > In response to this, would the following also be possible: classes.py: class Class1 pass class Class2(Class1) pass or would I still need to call it as: class Class2(classes.Class1) pass Also, I have seen the following syntax used once before, and havent found any documentation on it, any comments as to use, where to find docs, etc?: from module import x as name name.function() Thanks for the help, you explanation pretty much covered what I wanted to know, but also got some more questions! -- http://mail.python.org/mailman/listinfo/python-list
Re: Classes and Functions - General Questions
Andreas, and everyone else - thank you! I do appreciate the information and the quick responses, this single post with <10 replies has significantly helped my understanding level. Thanks again! -- http://mail.python.org/mailman/listinfo/python-list
