[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Jeff Allen
On 13/09/2023 17:21, MRAB wrote: I think the point is to have an equivalent to C#'s 'nameof'. It would be evaluated at compile time to a string, but with the advantage that it's clear that it's a name and not some random string that just happens to look like a name. I'd like to draw attentio

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Chris Angelico
On Sat, 16 Sept 2023 at 08:50, Jeff Allen wrote: > The parallel with f-string = is helpful, for which compile-time support is > essential, of course. It's really something that needs editor support, not compiler support. As far as the Python interpreter is concerned, this is just a string. So w

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Dom Grigonis
Yes, I agree. This was exactly what I had in mind. Was good to find out that there is such implementation in other language. DG. > On 15 Sep 2023, at 17:00, Jeff Allen wrote: > > On 13/09/2023 17:21, MRAB wrote: >> I think the point is to have an equivalent to C#'s 'nameof'. >> >> It would b

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Dom Grigonis
> def nameof(x): return x > > print("This " + nameof("thing") + " is:", thing) Can you explain what you meant by this code? How would this work in editor? > > ChrisA > ___ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send a

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Chris Angelico
On Sat, 16 Sept 2023 at 10:07, Dom Grigonis wrote: > > > > def nameof(x): return x > > > > print("This " + nameof("thing") + " is:", thing) > Can you explain what you meant by this code? How would this work in editor? > Frankly, I have no idea, because your **entire proposal** is predicated on so

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Dom Grigonis
So following this thread, from your perspective and from what has been said you can’t see or noticed any parts of it needing interpreter? DG > On 16 Sep 2023, at 03:14, Chris Angelico wrote: > > On Sat, 16 Sept 2023 at 10:07, Dom Grigonis wrote: >> >> >>> def nameof(x): return x >>> >>> pri

[Python-ideas] Re: Extract variable name from itself

2023-09-15 Thread Chris Angelico
On Sat, 16 Sept 2023 at 10:20, Dom Grigonis wrote: > > So following this thread, from your perspective and from what has been said > you can’t see or noticed any parts of it needing interpreter? Correct. Trying to get a variable name from an object is nonsensical, and trying to get a variable na