You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If every function in python is a new Block. Then in the code below, function D() call G() inside, G() return a Variable inside the g_scope,
it's hard to get variable from g_scope in d_scope.
There are several ways to do it:
we can use a pointer to collect all scopes and find inside them, but there will be many variables with the same name inside various scopes, it will be difficult to find the right variable.
we can copy the x in g_scope to scope when calling G() in D(), and then get it from the scope. this will import many variable copies but the copying is very expensive because some var may be very big.
why need
namespace
in PythonConclusion
Reasoning
Why Cannot Each Python Function Has a Block
If every function in python is a new Block. Then in the code below, function D() call G() inside, G() return a Variable inside the g_scope,
it's hard to get variable from g_scope in d_scope.
There are several ways to do it:
we can use a pointer to collect all scopes and find inside them, but there will be many variables with the same name inside various scopes, it will be difficult to find the right variable.
we can copy the x in g_scope to scope when calling G() in D(), and then get it from the scope. this will import many variable copies but the copying is very expensive because some var may be very big.
Namespace as a Solution
so we need a namespace in python to do name isolate.
Variable will have namespace as the prefix
x
inside G will beglobal/G/x
x
inside D will beglobal/D/x
all the variables are put inside on scope, so they can always find each other if the namespace and name is right.
The text was updated successfully, but these errors were encountered: