-3

What would be the equivalent to getfenv() in Python? Is there a way to get all available functions/variables in an environment?

Trying to see if something is sandboxed or not, which is why I am wondering this.

Jacob
  • 69
  • 14
  • [`dir()`](https://docs.python.org/3.1/library/functions.html#dir) – Tadhg McDonald-Jensen May 19 '16 at 20:39
  • What do you mean by sandboxed? – Peter Wood May 19 '16 at 20:41
  • nevermind, just looked at [lua documentation](https://www.lua.org/manual/5.1/manual.html#pdf-getfenv), I think you can get info on a specific stack frame by using `sys._getframe` and then inspecting the frame object. – Tadhg McDonald-Jensen May 19 '16 at 20:41
  • 3
    See http://stackoverflow.com/questions/7969949/whats-the-difference-between-globals-locals-and-vars for more on these topics. – a p May 19 '16 at 20:42
  • This question would be more useful if you said explicitly what *information* you want, instead of asking for the same information as a function in some other language. There probably isn't a single, exact equivalent. – jpmc26 May 19 '16 at 20:43

1 Answers1

1

I guess you are looking for globals()

>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', '__doc__': None, '__package__': None}
>>> 
>>> 
>>> foo = 1
>>> def bar():
...   pass
... 
>>> globals()
{'bar': <function bar at 0x102dd30c8>, '__builtins__': <module '__builtin__' (built-in)>, '__package__': None, '__name__': '__main__', 'foo': 1, '__doc__': None}
DevLounge
  • 8,313
  • 3
  • 31
  • 44