Python has a nice feature that gives the contents of an object, like all of it's methods and existing variables, called dir()
. However when dir is called in a function it only looks at the scope of the function. So then calling dir()
in a function has a different value than calling it outside of one. For example:
dir()
> ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
def d():
return dir()
d()
> []
Is there a way I can change the scope of the dir in d?