Oct-04-2021, 08:24 PM
(This post was last modified: Oct-04-2021, 08:25 PM by deanhystad.)
A variable is just a name. Think of it as a key in a namespace dictionary. The only thing you can use a variable for is getting or setting the object associated with the variable name. Even if you could somehow attach a name to a variable, it would do you no good. Your list vars does not contain any variables. It contains objects. vars has no association with the variable run1. vars[0] and run1 just happen to reference the same object, and that can change at any time. Variables do not provide you with a way to do what you want.
You'll get an error if you try to set the "name" attribute of a string or a list. These classes prohibit you from adding attributes (likely something in the __setattr__()). You probably cannot do what you want by attaching the name to the object.
You could create a new object that includes the name and the object.
You'll get an error if you try to set the "name" attribute of a string or a list. These classes prohibit you from adding attributes (likely something in the __setattr__()). You probably cannot do what you want by attaching the name to the object.
You could create a new object that includes the name and the object.
vars = [(var, f'name{i}) for i, var in enumerate(vars)]Since it appears the filename is based on the array index, why not generate the names when you need them?