help on "from deen import *" vs. "import deen"
jfong at ms4.hinet.net
jfong at ms4.hinet.net
Thu Nov 17 01:48:10 EST 2016
Steven D'Aprano at 2016/11/17 12:06:19PM wrote:
> You understand how this works?
Yes, thank you for your detail explanation.
> import russia as _tmp
> president = _tmp.president
> del _tmp
This one I can understand. But the previous one
>>_tmp = int('5')
>>for name in dir(_tmp):
>> if not name.startswith('_'):
>> locals()[name] = getattr(_tmp, name)
>>del _tmp
which I am still on scratching my head.
Now the question moves from "how" to "why":
Why "del _tmp" at the last step? The only reason I can thought of is "information hiding", but from whom? A global variable has its reason to be as a global. It may need to be modified later to influence others behavior. Using delete to hide the name seems unnecessary and redundant. If someone really want, he can follow the solution Chris had provided in his reply.
>>from deen import *
>>...
>>import deen
>>deen.some_name = new_value
A little strange, but effective:-)
--Jach
More information about the Python-list
mailing list