Is it possible to get the name of the variable passed to a function/class as a string? So if would pass the variable into a function I could use the name of variable inside as a string. How to change example function to get the str name:
var_passed = [1,2,3]
def fun(data_):
print(get_the_var_name_as_string)
fun(var_passed)
so it would give me string:
'var_passed'
My more complex example, where I would like to have the dataframe demo_data
used as some_data string variable:
import tkinter as Tk
from pandastable import Table
from demo import demo_data
import pandas as pd
class Result_pandastable(Tk.Frame):
"""Frame for panda dataframe with the pandastable module"""
def __init__(self, parent=None, dataframe_: pd.DataFrame = None):
self.parent = parent
Tk.Frame.__init__(self)
some_name = 'name'
self.main = self.master
self.main.geometry('800x800+200+100')
self.main.title('Results_'+ some_name)
self.tk_frame = Tk.Frame(self.main)
self.tk_frame.pack(fill=Tk.BOTH, expand=1)
self.df_steps = pd.DataFrame(data=dataframe_)
def draw_table(self):
self.table = pt = Table(self.tk_frame, dataframe=self.df_steps, showtoolbar=True, showstatusbar=True, showindex= True)
pt.show()
self.pack(fill=Tk.BOTH, expand=1)
self.mainloop()
def draw_table(dataframe_):
Result_pandastable(dataframe_= dataframe_).draw_table()
if __name__ == '__main__':
draw_table(demo_data)