I want to fetch all the variables and objects that were created in a python program with their types after it has finished execution. Suppose I have the following Python Script :
import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler
from configparser import ConfigParser
di = {'a':1,'b':2,'c':3}
df = pd.DataFrame(di)
config = ConfigParser()
min_max = MinMaxScaler()
new_features = []
Note : This script doesn't make any sense but has just been written for demonstration.
After this script has executed, we should get the following output. The output maybe in the form of a dictionary which can later be converted into a dataframe.
Variables | Type |
---|---|
di | dict |
df | DataFrame |
config | ConfigParser |
min_max | MinMaxScaler |
new_features | list |
While this can be done using the IPython magic command "whos" but it has limitation that it can only be used in Jupyter or IPython cell. I want a method that is independent of any platform.
Also, I don't want to add/modify anything to this file to get the output. Any function that can solve the problem should be run externally in a different python file.