Issue
Say there is a greetings module like this:
__all__ = []
def offer(func):
__all__.append(func.__name__)
return func
@offer
def spanish():
return "Hola!"
@offer
def japanese():
return "Konnichiwa"
When does the interpreter decide what to import when from greetings import *
is run?
Solution
When does the interpreter decide what to import when from greetings import * is run?
When you say from greetings import *
, interpreter loads and executes the greeting module, then it references the objects mentioned in the __all__
list back into the current module's global namespace so that you can access them using those symbols inside the __all__
.
I think you guessed because you defined __all__
at the beginning of the module and it's empty, nothing is going to be imported. No that's not the case.
Answered By - S.B Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.