Quick Question on importing..
stephen last edited by stephen
just my curiosity...
Would there be any benefit from "adopting" an import from another import?
import scene from scene import ui as gui class MyView(gui.View): ...
ccc last edited by ccc
>>> from scene import * >>> ui.ACTIVITY_INDICATOR_STYLE_WHITE_LARGE 0 >>> ui.ACTIVITY_INDICATOR_STYLE_WHITE 1 >>> class MyView(ui.View): ...
im just wondering if there is any benefit such as to overhead when doing this or if it makes no difference if i use, in this case, ui from scene or if i use scene and separate ui import?
ccc last edited by
Same thing either way...
>>> import ui >>> id(ui) 4543879592 >>> from scene import ui as gui >>> id(gui) 4543879592 >>> ui == gui True >>> ui is gui True
10-4 thanks @ccc
JonB last edited by
I think where this is usually used is when the module has a long name, and that you use a lot within your code, so for readability you use an abbreviation
import numpy as np from matplotlib import pyplot as plt
@JonB your statment on alias is correct 😃
But in this case we are speaking of Scene module importing
uiand then Developer using
uimodule through scene with without making a separate import of
uiin active script where
Inside scene.py ...
from _scene2 import * import _scene2 from scene_drawing import * import math from numbers import Number from io import BytesIO import ui DEFAULT_ORIENTATION = 0 PORTRAIT = 1 LANDSCAPE = 2 ...
inside myScript.py ...
from scene import ui class MyView(ui.View): ...