How to change module of a class in Python?

module, python

Solution

Foo.__module__ = __name__

Change the module name explicitly. You can have the `make_class` function handle this if you have it take a module name argument for the new class's `__module__` attribute.

Problem

module1 have funcion make_class. module2 calls it this way: ``` Foo = make_class('Foo') ``` or this: ``` setattr(sys.modules[__name__], 'Foo', make_class('Foo')) ``` But in either case we have `<class 'module1.Foo'>` how to assign this class to module2: `<class 'module2.Foo'>`? (I need this to fulfill the requirements of SQLAlchemy)

Original source