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!
I did some googling for "flask support multiple API versions", and found this stackoverflow post to be pretty handy.
In short, the only real difference suggested in that post vs what you've provided is that they use subdirs for each version, and each version is a module itself.
If you're able/allowed to share common functions/objects between versions, this structure might make maintaining/managing your module easier.
some_package
+--- my_module/
+--- v1_0/
+--- __init__.py
+--- some_file.py
+--- v2_0/
+--- __init__.py
+--- some_file.py
+--- __init__.py
+--- common_stuff.py
But if you cannot share things between versions, then your current idea works just fine, and is simpler.
And then you could import it like this:
import my_module.vX_Y as my_module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With