On 1/22/20 8:05 AM, Anders Hovmöller wrote:
On 22 Jan 2020, at 13:23, Rhodri James
wrote: On 22/01/2020 12:03, Anders Hovmöller wrote:
He was pretty clear in saying he wanted the same thing as in C#. That no one in this thread seems to have looked that up is really not his fault in my opinion. Oh, plenty of people have looked it up. The problem is that it relies on part of the nature of C# (variables are lvalues) that simply isn't true in Python, which I don't think the OP realised. Does it? How? https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/... seems pretty clear to me that it's a rather simple extraction of an AST node, lvalue or not doesn't seem relevant at all.
Can you point me to something where this isn't the case?
The part from the C# docs that people perhaps overlooked is that nameof is a compile-time function. It has access to the variable's name not just its value. Definitely, a runtime-function in Python has enormous challenges in trying to replicate this behavior. Not that I'm advocating adding something like this... --Ned.