1

I would like to create a utility function that filters variables in my current environment and prints them (ie print all variables that have type pd.core.frame.DataFrame) and then put this function in my utils module. I used (Pandas Get a List Of All Data Frames loaded into memory):

import pandas as pd
def list_my_frames():
    f = [var for var in dir() if isinstance(eval(var), pd.core.frame.DataFrame)]
    return f

I would like to be able to pass my current environment to dir() so that I can use it outside of my utils module. How can I get a handle to my current environment in python?

Alex
  • 1,281
  • 1
  • 13
  • 26
  • why not create a function that accepts the product of `dir()` ? – moshevi Jul 25 '18 at 21:12
  • plus use `vars()` instead of `dir()` no need for `eval`. – moshevi Jul 25 '18 at 21:16
  • is there a way to simply pass a handle to the scope in which `list_my_frames` is being evaluated in and then pass that on to `dir`? ie `list_my_frames(my_scope): ...dir(my_scope)`? – Alex Jul 25 '18 at 21:38

0 Answers0