python - Import function from module without losing module identifier -
this question has answer here:
i'm looking way import single function module, without losing module name function name. example,
from os import remove
leaves me function called 'remove'; it's not clear, elsewhere in code, comes os
module. however, throws syntax error:
from os import remove os.remove
this satisfactory (and possible):
from os import remove os_remove
but again it's not clear comes os module; lovely keep dot in if possible
why want this? well, here premises led me investigate - if can tell me of these flawed excellent thing learn in itself:
if you're going use 1 function module, it's more efficient import import whole module.
if using, say,
os.remove
in code, it's clearer labelled such, it's transparent else function , how behave. of course, discernable import statement, seems useful throughout code.
if isn't possible, i'd interested learn stops it.
your first premise flawed. there no difference in importing 1 function vs whole module.
in order import module, python must first read, parse , execute entire module. difference in importing 1 function vs whole thing name gets allocated in current namespace: in case, 1 name module, or 1 name function. in other words, no difference @ all.
Comments
Post a Comment