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

2023-11-08 Thread anthony.flury via Python-ideas
4 Nov, 23 At 08:13 Subject: [Python-ideas] Re: Extract variable name from itself A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The i

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

2023-11-08 Thread Rene Nejsum
A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The instance of CharField knows that it's variable name is "user_name", so that it can name the row i

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

2023-09-28 Thread Dom Grigonis
Just want to clear things out that I did not respond to immediately due to obvious reasons. > On 25 Sep 2023, at 07:44, Tiago Illipronti Girardi > wrote: > Can you please stop manufacturing consent? It is not what you stated it is. It was something different. An example of manufacturing consen

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

2023-09-25 Thread Chris Angelico
On Mon, 25 Sept 2023 at 22:04, Dom Grigonis wrote: > > I think a lot has been said by this time and I have nothing to add. > > If this is something that is of value, I am sure it will be picked up when > the time is right. > > One last thing that I think could be of some use is a poll: > > https:

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

2023-09-25 Thread Dom Grigonis
I think a lot has been said by this time and I have nothing to add. If this is something that is of value, I am sure it will be picked up when the time is right. One last thing that I think could be of some use is a poll: https://take.supersurvey.com/QCVZKTDY0

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

2023-09-24 Thread Tiago Illipronti Girardi
Can you please stop manufacturing consent? Em dom., 24 de set. de 2023 às 21:06, Dom Grigonis escreveu: > What is your position on this? > > Do you think that such thing is worth having? > > If yes, do any of the 3 final options seem sensible to you? > > > On 25 Sep 2023, at 02:39, Chris Angelic

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

2023-09-24 Thread Chris Angelico
On Mon, 25 Sept 2023 at 10:05, Dom Grigonis wrote: > > What is your position on this? > > Do you think that such thing is worth having? > > If yes, do any of the 3 final options seem sensible to you? > My position is that so far, you haven't shown it to be of much value. Which might be because th

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

2023-09-24 Thread Dom Grigonis
What is your position on this? Do you think that such thing is worth having? If yes, do any of the 3 final options seem sensible to you? > On 25 Sep 2023, at 02:39, Chris Angelico wrote: > > On Mon, 25 Sept 2023 at 07:05, Dom Grigonis wrote: >> What I meant is that functions in __builtins__ a

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

2023-09-24 Thread Chris Angelico
On Mon, 25 Sept 2023 at 07:05, Dom Grigonis wrote: > What I meant is that functions in __builtins__ are low level, with > functionality which is hidden from the user. > What does that even mean? ChrisA ___ Python-ideas mailing list -- python-ideas@pyt

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

2023-09-24 Thread Dom Grigonis
> 'Esoteric' means something hidden, it is the exact opposite of 'we all know > about' What I meant is that functions in __builtins__ are low level, with functionality which is hidden from the user. So my point is that it seems like an appropriate place for nameof(). After all, f’{v!}’ applies

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

2023-09-24 Thread Tiago Illipronti Girardi
Appling my specific advice elsewhere is at most cute, in this case it was offensive, and I doubt it was only to me. The `'f{name!id}'` syntax is what *I* prefer, but *I* think that subclassing typing.LiteralString is less disruptive. 'Esoteric' means something hidden, it is the exact opposite of

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

2023-09-24 Thread Dom Grigonis
> On 24 Sep 2023, at 19:27, Tiago Illipronti Girardi > wrote: > > There definitely is a miscommunication: > > The 2 first options was me spitballing an alternative against the third. > > The not reinventing the wheel remark was me saying that the particular > example that you gave *on that

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

2023-09-24 Thread Tiago Illipronti Girardi
There definitely is a miscommunication: The 2 first options was me spitballing an alternative against the third. The not reinventing the wheel remark was me saying that the particular example that you gave *on that particular message* can already be done. Also the case 2 f'{name!i}', I suggested

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

2023-09-24 Thread Dom Grigonis
I think the separation is needed between the 2: a) identifier name b) expression text I think there is a mix-up between these 2 which causes some confusion (at least to me). Wanting both made me cling to f-strings as they currently do b) in ‘postfix=' and a) can be extracted from it. — I

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

2023-09-24 Thread Dom Grigonis
> On 24 Sep 2023, at 17:23, Chris Angelico wrote: > > On Mon, 25 Sept 2023 at 00:15, Dom Grigonis wrote: >> I see what you mean, but this property is arguably intrinsic to what it is. >> And is part of f-strings vs explicit formatting property too: >> >> variable = 1 >> print(f'{variable=} a

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

2023-09-24 Thread Tiago Illipronti Girardi
or print('{a=} and b={a}') This already exists. Kindly stop reinventing the wheel. the thing that does not exist now is: print('In this context, variable', 'name', 'means an esoteric thing that we all know about') where `'name'` can be substituted easily (the 'nameof' case) but it could be,

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

2023-09-24 Thread Chris Angelico
On Mon, 25 Sept 2023 at 00:15, Dom Grigonis wrote: > I see what you mean, but this property is arguably intrinsic to what it is. > And is part of f-strings vs explicit formatting property too: > > variable = 1 > print(f'{variable=} and b={variable}') > # VS > msg = 'variable={v} and b={v}' > prin

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

2023-09-24 Thread Dom Grigonis
> On 24 Sep 2023, at 16:42, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >>> But it's far from concise >> What could be more concise? > > A notation where you don't have to repeat a possibly long expression. > For example, numerical positions like regular expressions. Consider >

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

2023-09-24 Thread Tiago Illipronti Girardi
The problem is that `f'{exp,format}'` is the current 'status quo'/'zeitgeist' You are trying to invert it. It looks wrong. (That's taste, not technical, if you don't think it is a problem, it isn't a problem for *you*) The technical: `f'{=name}'` doesn't tell what you're trying to do if you don't

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

2023-09-24 Thread Stephen J. Turnbull
Dom Grigonis writes: > > But it's far from concise > What could be more concise? A notation where you don't have to repeat a possibly long expression. For example, numerical positions like regular expressions. Consider this possible notation: f'There are {count} expression{pluralize(count

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

2023-09-24 Thread Dom Grigonis
> But it's far from concise What could be more concise? > and > violates DRY -- it doesn't solve the problem of the first draft typo. And how is “postfix =“ different? > I don't see it as elegant the way "postfix =" is. Agreed. DG ___ Python-ideas mai

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

2023-09-24 Thread Stephen J. Turnbull
Dom Grigonis writes: > By “elegant", I wasn’t talking about the syntax. Neither was I, except in the comment about "mnemonic". I use "postfix =" and "prefix =" because I don't know of better names that indicate the semantics of the feature. Semantically, "prefix =" is a reasonable solution to

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

2023-09-23 Thread Dom Grigonis
I haven’t given much thought regarding the syntax. The prefix “=“ just popped into my mind and I went along with it to use in my examples. The point was that f-strings are potentially a good place to implement such thing. By “elegant", I wasn’t talking about the syntax. It was more about the ben

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

2023-09-23 Thread Stephen J. Turnbull
Dom Grigonis writes: > Eric Smith wrote: >> Since I wrote that commit: no one is saying it’s impossible or >> overly difficult, > To be honest it is exactly what was being said. Sure ... about an unclearly expressed early version of the proposal, that seemed to ask "given an object x, te

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

2023-09-23 Thread Eric V. Smith via Python-ideas
On Sep 23, 2023, at 5:37 PM, Dom Grigonis wrote:It seems that my guess was correct. There was a commit, when only the first part was working:https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d23cfc52b5e07e4381aSince I wrote that commit: no one is saying it’s impossible or

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

2023-09-23 Thread Dom Grigonis
> Since I wrote that commit: no one is saying it’s impossible or overly > difficult, To be honest it is exactly what was being said. > just that the benefit of having it doesn’t justify the cost of adding it. I can understand that. > I understand that you think it’s worth the cost. No, I don’t

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

2023-09-23 Thread Dom Grigonis
It seems that my guess was correct. There was a commit, when only the first part was working: https://github.com/python/cpython/pull/13123/commits/67977672360659f203664d23cfc52b5e07e4381a So it does

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

2023-09-23 Thread Dom Grigonis
> the output will have the expression text This is exactly what I want. If there was an extra check for validity at parser level, it is a plus. > You want to produce a name, that is an identifier > . Not necessarily, I want

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

2023-09-23 Thread Dom Grigonis
> On 23 Sep 2023, at 16:24, Tiago Illipronti Girardi > wrote: > > but: > 1. There are costs doing it in python. And easy implementation doing it in > editor (with the typing support it's almost already done). What are those costs? > 2. The f-string functionality is not there right now, but f'

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

2023-09-23 Thread Tiago Illipronti Girardi
but: 1. There are costs doing it in python. And easy implementation doing it in editor (with the typing support it's almost already done). 2. The f-string functionality is not there right now, but f'{name!id}' would leverage what is there and, with editor support, give the exact `nameof`` support e

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

2023-09-23 Thread Dom Grigonis
> This is the only use case I can think of. Yes, probably most common one, but I have mentioned couple more. 1. Keeping dictionary keys in sync with variable name. 2. eval / exec statements. Although eval / exec are not recommended in high standard production code, python is widely used in plugin

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

2023-09-23 Thread Tiago Illipronti Girardi
This is the only use case I can think of. It could be supported by the typing module by subtyping LiteralString and let the editor tools do the rest. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le

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

2023-09-23 Thread Pyrous
>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 why not just make it an editor feature?>def nameof(x): return x>print("This " + nameof("thing") + " is:", thing)>As far as I can tell, this isn't a Python

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

2023-09-23 Thread Dom Grigonis
> On 23 Sep 2023, at 08:54, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >> Simply eval/exec string inputs. I sometimes use of these for ad-hoc >> callbacks. Would be great if `v` was recognised as a code. > > Looking at the example, do you mean '=' here? That is, you want to > a

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

2023-09-22 Thread Stephen J. Turnbull
Dom Grigonis writes: > Simply eval/exec string inputs. I sometimes use of these for ad-hoc > callbacks. Would be great if `v` was recognised as a code. Looking at the example, do you mean '=' here? That is, you want to add semantics for prefixed '=', meaning "just insert the expression string

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

2023-09-22 Thread Dom Grigonis
Just want to add to this as I encountered a case, where I think f-string would be sensible to use. Third potential use case after logging & dictionary key synchronisation with variables names. Simply eval/exec string inputs. I sometimes use of these for ad-hoc callbacks. Would be great if `v` w

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

2023-09-18 Thread Dom Grigonis
Thank you Jonathan, This is indeed helpful, I have completely forgotten about these. However, in my case, defaults are not callable defaults, but rather default values preset at a higher level object and it has little to do with function defaults. Although, I think it is possible to reshape th

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

2023-09-18 Thread Jonathan Fine
Hi Dom In your original post you used your proposed addition to write code that provides a way of handling defaults different from the standard mechanism, and perhaps in your opinion better. The following example tells us something about defaults mechanism already provided by Python: >>> def f(a

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

2023-09-17 Thread Dom Grigonis
Thank you Jonathan, Could you please elaborate on your suspicion, that my proposed addition will make bad code easier to write? It would be nice if you provided example, where there is a pattern using my proposed addition, where similar badness of code cant be achieved using already existing p

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

2023-09-17 Thread Jonathan Fine
Hi Dom To support your proposal you provided an example. Well done for providing evidence to support your idea. Doing that makes the discussion more productive. I'm going to use the words 'good' and 'bad', but with two provisos. The first is that they are judgemental, and often judgement is littl

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

2023-09-16 Thread Dom Grigonis
Hi Jonathan, I wasn’t writing anything specialised on handling of defaults. My initial example pretty much covers it. What defaults handler of python are you talking about? This proposal is more about convenient refactoring and keeping things nicely synchronised where variable name and string

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

2023-09-16 Thread Jonathan Fine
Hi Dom In your original post you said you're writing some code to improve handling of defaults (perhaps only in some situations). You also said that the feature you're suggesting would make your improved default handler easier to write. Python already handles default values at least fairly well i

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

2023-09-16 Thread Dom Grigonis
Agree, all good points. f'{=expr}'.split('.')[-1] Does take care of all cases and `nameof` has no additional use over it. It seems that `nameof` is out of question. DG > On 16 Sep 2023, at 19:50, Stephen J. Turnbull > wrote: > > Dom Grigonis writes: > >> print(f'{=A.a}')# 'A.a' >> print(

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

2023-09-16 Thread Stephen J. Turnbull
Dom Grigonis writes: > print(f'{=A.a}')# 'A.a' > print(nameof(A.a)) # 'a' I see that's the C# semantics, but it's not obvious to me why the ambiguity introduced is worth emulating. The important aspect of the proposed 'nameof' operator is that its argument can be validated by the compiler

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

2023-09-16 Thread Dom Grigonis
If it is done at a tool level, it is not a robust solution. The fact that it can be done in a tool doesn’t mean that it is the optimal solution. Having it done at python level could be a simpler solution and provide benefits to all of the tools, without needing for editor logic to deviate from p

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

2023-09-16 Thread Bruce Leban
If the goal is to create a syntax that allows tools to recognize names in strings, there is a simple solution which requires tool changes only, for example: raise Exception('The field ' + ((('size'))) + ' must be a positive integer in ' + ((('Sample.widget' Python already treats triple parent

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

2023-09-16 Thread Chris Angelico
On Sat, 16 Sept 2023 at 19:48, Jeff Allen wrote: > It needs language (parser) support because it does what you identified early > on: "take whatever is given and put it in quotes", where "whatever is given" > is the text of the expression only available at run-time. > I didn't say "and put it i

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

2023-09-16 Thread Jeff Allen
On 16/09/2023 11:33, Dom Grigonis wrote: It works already with existing tools that will treat "nameof(a+b)" as a function call, which it is syntactically but not semantically, so renaming b to c will now produce the string "a+c". I think my IDE does offer to do this with variable names in str

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

2023-09-16 Thread Dom Grigonis
Yes, it seems it does have scope beyond editor in both cases. class A: a = 1 print(f'{=A.a}')# 'A.a' print(nameof(A.a)) # 'a' In f-string case, if to be consistent with current f-string functionality, expression would be checked for a validity and that reference is in scope and available.

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

2023-09-16 Thread Jeff Allen
On 16/09/2023 01:14, Chris Angelico wrote: But if that tool can be taught that nameof indicates a variable name, then it can rename inside it just like it would rename anything else. It works already with existing tools that will treat "nameof(a+b)" as a function call, which it is syntactically

[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

[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: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
> 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 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 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 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-14 Thread Dom Grigonis
Good ideas, however not robust: a = 1 b = 1 print(id(a))# 4536318072 print(id(b))# 4536318072 > On 14 Sep 2023, at 16:35, Jonathan Fine wrote: > > POSTSCRIPT > > We can also use locals() to 'inverse search' to get the name, much as in the > original post. > > >>> locals()['x'] > (0, 1

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

2023-09-14 Thread Stephen J. Turnbull
Jonathan Fine writes: > We can also use locals() to 'inverse search' to get the name, much > as in the original post. As has already been explained, locals() (and any namespace for that matter) is a many-one mapping, and therefore the inverse is not well-defined. At least for the 'print(f"coun

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

2023-09-14 Thread Jonathan Fine
POSTSCRIPT We can also use locals() to 'inverse search' to get the name, much as in the original post. >>> locals()['x'] (0, 1, 2, 3) >>> id(x) 139910226553296 >>> id(locals()['x']) 139910226553296 -- Jonathan ___ Python-ideas mailing list -- python-id

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

2023-09-14 Thread Jonathan Fine
Perhaps use the id of an object instead of its value. Here's how it might work >>> store = {} >>> def wibble(fn): ... val = fn() ... name = fn.__name__ ... store[id(val)] = name ... return val >>> @wibble ... def ddd(): ... return tuple(range(4)) >>> ddd (0, 1, 2, 3)

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

2023-09-13 Thread MRAB
On 2023-09-12 16:54, Rob Cliffe via Python-ideas wrote: On 12/09/2023 11:54, Dom Grigonis wrote: Yes, Thank you! So 2 solutions now. They both solve what I have encountered. Beyond that, they differ by: a) f-string print(f’{=a.method}’) # ‘a.method’ No new builtin needed.

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

2023-09-12 Thread Rob Cliffe via Python-ideas
On 12/09/2023 11:54, Dom Grigonis wrote: Yes, Thank you! So 2 solutions now. They both solve what I have encountered. Beyond that, they differ by: a) f-string print(f’{=a.method}’) # ‘a.method’ No new builtin needed. Simply reprints expression representation. I don't unde

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

2023-09-12 Thread Dom Grigonis
I agree. What I meant is that it is unreliable with `v is 710` and even more unreliable with `v == 710` as “==“ is less strict than “is”. DG > On 12 Sep 2023, at 21:03, Rob Cliffe wrote: > > >>> As for the example in your first post: >>> var = 710 >>> variable_name = [k for k, v in locals().

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

2023-09-12 Thread Rob Cliffe via Python-ideas
As for the example in your first post: var = 710 variable_name = [k fork, v inlocals().items()ifv == 710][0] print("Your variable name is "+ variable_name) it does "work", but it doesn't make much sense with Python's semantics.  You could have two identifiers bound to the same object; which o

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

2023-09-12 Thread Dom Grigonis
Good points, thanks for reply. > Or do you want to check that the expression can be evaluated at run time? > You could achieve that by simply writing > a.method Yes, the point is that it would be checked for legality of expression itself. Whether to check if it actually evaluates without an e

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

2023-09-12 Thread Dom Grigonis
Yes, Thank you! So 2 solutions now. They both solve what I have encountered. Beyond that, they differ by: a) f-string print(f’{=a.method}’) # ‘a.method’ No new builtin needed. Simply reprints expression representation. b) print(nameof(a.method)) # ‘method’ New builti

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

2023-09-12 Thread Dom Grigonis
An addition to f-strings: a = 1 b = 1 print(f'{a+b}') # '2' print(f'{a+b=}') # 'a+b=2' # I suggest adding this too print(f'{=a+b}')# 'a+b' It is different from putting it in quotes in a way how editors interpret it. E.g. changing the variable name in PyCharm would unambiguously change

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

2023-09-12 Thread Valentin Berlier
Do you mean something like C# nameof()? https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mai

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

2023-09-12 Thread Chris Angelico
On Tue, 12 Sept 2023 at 20:05, Dom Grigonis wrote: > > Please read the next part of my e-mail too. It actually answer your question. > I did read it, and it didn't answer the question. Your desired semantics are not clear. ChrisA ___ Python-ideas maili

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

2023-09-12 Thread Dom Grigonis
Please read the next part of my e-mail too. It actually answer your question. > On 12 Sep 2023, at 13:00, Chris Angelico wrote: > > On Tue, 12 Sept 2023 at 19:51, Dom Grigonis wrote: >> >> It wouldn’t. I know this is weird and not in line of how things work. This >> is more about simply getti

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

2023-09-12 Thread Chris Angelico
On Tue, 12 Sept 2023 at 19:51, Dom Grigonis wrote: > > It wouldn’t. I know this is weird and not in line of how things work. This is > more about simply getting reference variable name in locals() from the > reference itself. But how would one access the variable name, when once > called it ret

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

2023-09-12 Thread Dom Grigonis
It wouldn’t. I know this is weird and not in line of how things work. This is more about simply getting reference variable name in locals() from the reference itself. But how would one access the variable name, when once called it returns the object it points to, not itself. So this would obviou

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

2023-09-12 Thread Antoine Rozo
Why would an object always be linked to a variable name, and why only one name? Le mar. 12 sept. 2023 à 10:23, Dom Grigonis a écrit : > As far as I understand, it is not possible. Is it? > > Something similar to: > > var = 710 > variable_name = [k for k, v in locals().items() if v == 710][0] > p