On Wed, Jan 22, 2020 at 11:57 PM Richard Damon <rich...@damon-family.org> wrote:

> Thus nameof(x) can ONLY be "x" in Python (or an error is x isn't
> something that is a name), as at best x is referring to some object, but
> that object doesn't have a special name to refer to it that is its
> holder.  Yes, one example where that linkage might be useful is it
> documents in the code that the string value is actually supposed to be
> the name of the variable, so a refactoring that changes the variable
> should change the string too, such a semantic link between a variable
> and its spelling is ill advised, and would only be used in a debugging
> environment with something like print("x", x) or some similar purpose
> function, and in that context, such prints should not normally be long
> lived or are part of long term logging in which case the stability of
> the label might actually be preferred to not break parsers for the log
> output.
>

For the record, this sort of debugging purpose IS important to Python,
and f-strings have a special facility for this:

>>> x, y = 1234.5, "spam"
>>> print(f"Before flurblization: {x=} {y=}")
Before flurblization: x=1234.5 y='spam'

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/RKAGBJTBZP6N2ULIRJIPOCXYPG2JZ4JK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to