Distributing methods of a class across multiple files

Roy Smith roy at panix.com
Tue Jan 24 23:05:35 EST 2012

In article 
<569a94a3-cd84-449b-b0c1-80348014aac6 at i10g2000pbl.googlegroups.com>,
 lh <lhughes42 at gmail.com> wrote:

> Is this possible please?  I have done some searching but it is hard to
> narrow down Google searches to this question. What I would like to do
> is, for example:
> 1) define a class Foo in file test.py... give it some methods
> 2) define a file test2.py which contains a set of methods that are
> methods of class Foo defined in test.py.  I can import Foo obviously
> but it isn't clear to me how to identify the methods in test2.py to be
> methods of class Foo defined in test.py (normally I would just indent
> them "def"'s under the class but the class isn't textually in
> test2.py).
> In short I would like to distribute code for one class across multiple
> files so a given file doesn't get ridiculously long.

The student asks the master, "How long is a file?"

The master replies, "Just long enough to hold its contents".

"But, what if my class is ridiculously long?  Won't the file that 
contains it also be ridiculously long?"

"Just as one cannot count the grains of sand on a beach, neither can one 
count the number of kilobytes one can buy for a few cents at your local 
office supply store"

And the student was enlightened and stopped thinking the whole world was 
Java or C++.

More information about the Python-list mailing list