define class over 2 files

Steven D'Aprano steven at
Tue Aug 18 07:57:46 CEST 2009

On Mon, 17 Aug 2009 21:45:57 -0700, naveen wrote:

> Is it possible to split up a class definition over multiple files?

Not exactly, but you can do variations of this:

In file, create:

class Parent:
    def method(self):
        return "Method"

In file, do this:

import A
class Child(B.parent):
    def another_method(self):
        return "Another Method"

Now your class Child has two methods, method() and another_method().

Similarly, you can do this:

# File

def function(x, y):
    return x+y  # or something more complicated

# File

import A

def MyClass(object):
    def func(self, x, y):
        return A.function(x, y)


More information about the Python-list mailing list