There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in #get-help.
Agree with a comment or answer? Like () to up-vote the contribution!
How do I access the parents namespace from within an enclosed function?
I noticed the locals() only returns the variables from the function itself, globals() returns the same global namespace as when called from the main code. Hence my question, how can I get the object’s parent namespace?
I don’t think there’s a standard route to access all the names from the enclosing (function) scope. Don’t forget that the effective ‘namespace’ of a function only really has a meaning during a function call and the actual objects are forgotten afterwards. Closures are a very special case where an additional reference to an object from the outer scope is effectively captured by an inner function.
Therefore inside an inner function that used names from the enclosing scope the only enclosing scope names you’d have direct access to are those that were used when the (inner) function was first defined (so you already have references for them anyway).
It’s a bit of a complex implementation detail that you probably don’t need to worry about. In short, there is no simple way to do this.