is it possible to dividing up a class in multiple files?

roelmathys at gmail.com roelmathys at gmail.com
Tue Aug 8 16:45:34 EDT 2006


Martin Höfling wrote:
> Hi there,
>
> is it possible to put the methods of a class in different files? I just
> want to order them and try to keep the files small.
>
> Regards
> 	Martin

you could do this:

file_1.py:

class A:
    def __init__(self):
        self.a = 1

file_2.py:
from file_1 import A

def seta(self,value):
    self.a = value

setattr(A,"seta",seta)

but to use the "complete" class you should then import file_2 in other
source files.

bye
rm




More information about the Python-list mailing list