I looked around but cannot find a clear answer to my question.
I have a very legitimate need for supporting N-versions of the same Python module.
If they are stored in the same same package/directory, they would have to be uniquely named, like in the following example:
.../some/package/my_module_1.0.py
.../some/package/my_module_1.1.py
.../some/package/my_module_2.0.py
-- etc. --
And each would, in turn, store its version number via the "version" attribute.
The consuming program then imports the correct version that it needs (e.g.: import my_module_1.1).
Is this the optimal (and most pythonic) way to accomplish this multi-module version need?
Thank you!
my_module_*
, you might be able to keep the syntax compatible with more than one version. For example,except Exception, e:
is valid syntax in Python2, but not in Python3, so you should useexcept Exception as e:
because it is valid in both versions. – Seleuciasys.__modules__
, which contains a dictionary of imported modules keyed by name, usually the file name. You might be able to hide the versioning issue by importing the right module and always storing it under the same key, regardless of what its actual file name is. – Darill