Is It Possible To Detect Way Of Import Of A Module In Python?
Imagine you have module foo containing variable bar and thread baz that automagically updates bar: from threading import Thread import sys bar = 0 class baz(Thread): def run(self
Solution 1:
No. One reason is that a module can be imported many times, from many places. It could be imported with import foo
in one place and from foo import *
in another. Nothing will "happen" on the second import (the already-imported module in sys.modules
will be used), so your module has no way of detecting it.
Post a Comment for "Is It Possible To Detect Way Of Import Of A Module In Python?"