I know that import *
is bad, but I sometimes use it for quick prototyping when I feel too lazy to type or remember the imports
I am trying the following code:
from OpenGL.GL import *
shaders.doSomething()
It results in an error: `NameError: global name 'shaders' is not defined'
If I change the imports:
from OpenGL.GL import *
from OpenGL.GL import shaders
shaders.doSomething()
The error disappears. Why does *
not include shaders
?
If shaders
is a submodule and it’s not included in __all__
, from … import *
won’t import it.
And yes, it is a submodule.
shaders
is a submodule, not a function.
The syntax from module import something
doesn't import submodules (Which, as another answer stated, not defined in __all__
).
To take the module, you'll have to import it specifically:
from OpenGL.GL import shaders
Or, if you only want to have a few functions of shaders
:
from OpenGL.Gl.shaders import function1, function2, function3
And if you want to have all the functions of shaders
, use:
from OpenGL.Gl.shaders import *
Hope this helps!
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