Distributing methods of a class across multiple files

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Jan 25 06:49:37 EST 2012


lh 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.
>
> Thank you,
>  Luke
>   

If the file is ridiculously long, could be that the class has a 
ridiculous number of methods. If you spread your class into multiple 
files, you will have a ridiculous number of tiny files with ridiculous 
names.

My 2 cents : keep 1 class in 1 file, and keep your scopes consistent.

JM



More information about the Python-list mailing list