0

If I have a variable, say:

variable_name = 1

I am not able to easily regain the name I gave to the variable, in this case: "variable_name" Therefore I was wondering if there is a method assign_variable to assign a variable but at the same time to record the name used to a list or a dictionary etc. ?

variable_name_list =[]
variable_name_list.append(assign_variable(variable_name = 1))

print(variable_name_list)

["variable_name"]

variable_name + 2

3

EDIT: All variables get recorded in a namespace, but the issue is that I want to call a function from another .py file and this function should then get the variable names from the variable in the current file.

henry
  • 875
  • 1
  • 18
  • 48

1 Answers1

0

Using a dictionary, you can use:

dict = {"variable name": variable value}
print(dict["variable name"])

prints out variable value

balexander1
  • 182
  • 1
  • 1
  • 8