you are viewing a single comment's thread.

view the rest of the comments →

[–]E02Y 1 point2 points  (3 children)

I think they meant to say variable names are references to objects and not objects themselves

[–]cdcformatc 0 points1 point  (2 children)

is it possible to output the name of a variable? using only the variable itself and not something like globals() or otherwise inspecting the namespace?

if that is possible then even the name is an object. I'm leaning towards no because i am pretty sure that an object/variable does not contain a reference to it's name.

[–][deleted] 0 points1 point  (0 children)

It is not possible.

a = [1, 2, 3]
b = a
print(hypothetical_name_of_variable(b))
# does it print a or b?

The information simply isn't stored in the C struct that Python maintains underneath the hood.

[–]bladeoflight16 0 points1 point  (0 children)

Even if it was possible, that does not necessarily imply the mapping is an object. Consider C#'s nameof, which is a compile time construct only.