This is a followup to function that returns a dict whose keys are the names of the input arguments, which I learned many things (paraphrased):
- Python objects, on the whole, don't know their names.
- No, this is not possible in general with
*args
. You'll have to use keyword arguments - When the number of arguments is fixed, you can do this with
locals
- Using globals(). This will only work if the values are unique in the module scope, so it's fragile
- You're probably better off not doing this anyway and rethinking the problem.
The first point highlighting my fundamental misunderstanding of Python variables. The responses were very pedagogic and nearly instantaneous, clearly this is both a well-understood yet easily confused topic.
Since I'd like to learn how to do things proper, is it considered bad practice to create a dummy class to simply hold the variables with names attached to them?
class system: pass
S = system ()
S.T = 1.0
S.N = 20
S.L = 10
print vars(S)
This accomplishes my original intent, but I'm left wondering if there is something I'm not considering that can bite me later.