I was sure that I had at least some basic understanding of the Python visibility system. Now I get an error message and, unfortunately, I can not write a good piece of code for playback yet. I tried to reproduce it in a new small project, but everything works as I expect, there: - /
I can only describe what I am doing, and I hope someone discovers a sample and can tell me what may be going wrong.
First there is a python x.py file that implements class X
In another python file, the following line exists:
code=""" ... from x import X ... class Y(X): # does not crash here, ... def __init__(self): X.__init__(self) # ... but here ... foo=Y() """
You can assume that python can find the X module. At some point, I'm trying to accomplish this:
exec(code, globals(), locals())
And now I get a NameError . He tells me that X not defined when he tries to call its constructor. Obviously, a few lines were defined above.
If I change Y.__init__ with the addition of from x import X to the first line, it works. But why the hell should I import it there?
As already stated, the actual code is more complex and does more things. In an unsuccessful case, my publication does not even show the part that actually leads to the problem. But perhaps you have some general ideas on how to achieve this behavior.
source share