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 understand your semantics either. What would be the difference
between your proposed
print(f’{=a.method}’)
and simply writing
print('a.method')
?
Would it be just that the syntax inside the curly braces is checked for
legality,
so that
print(f'{=!?}')
would not be allowed (presumably it would cause a SyntaxError)
?
Or do you want to check that the expression can be evaluated at run time?
You could achieve that by simply writing
a.method
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 one you
got hold of would be essentially random.
Puzzled.
Rob Cliffe
_______________________________________________
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/GTDF4Q2OYWWSTHWXTQI6TSEXHJIRWX4Z/
Code of Conduct: http://python.org/psf/codeofconduct/