python - Is it safe to modify the output of globals()? -
the documentation locals() function warns not modify output, interpreters may not reflect changes in local scope. i'm assuming means python spec doesn't require it, though works in cpython.
i'd know if same globals(). there's no warning in the documentation, find strange differ each function apparently performs same action on different scope.
if it's safe, modifying globals()' output improve simplicity , compatibility of project i'm working on.
modifying locals()
doesn't work reliably, in cpython. happens work in module , class scopes, fails inside function (any modifications "won't take", since locals()
provides copy of local namespace in case, rather reference real thing)
however, globals()
different, since always refers module namespace, , module namespaces required behave ordinary dictionaries. yes, lack of warning on globals()
isn't oversight, allowed.
Comments
Post a Comment