2021年3月29日星期一

Split and recombine a Python module

I have a Python module, let's call it my_lib.py which has grown too much in size and would like to split it up into two modules: lib_a.py and lib_b.py However, the module is already used in several places:

import my_lib  my_lib.func_a()  my_lib.func_b()  

In my new module partition, func_a() and func_b() end up in lib_a and lib_b respectively. I would have to change the above code to something like this:

import lib_a, lib_b  lib_a.func_a()  lib_b.func_b()  

This is undesirable for backwards compatibility. What's the best way to keep referring to the two new modules as "my_lib"? Is it possible to recombine the two libraries into a new one called "my_lib" and keep using the legacy code?

https://stackoverflow.com/questions/66863528/split-and-recombine-a-python-module March 30, 2021 at 09:06AM

没有评论:

发表评论