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 error or not would both work. I see pros and cons in both cases. Maybe not evaluating is better as evaluation can always be checked separately if needed and eventually will be checked on actual usage anyway.
> As for the example in your first post: > var = 710 > variable_name = [k for k, v in locals().items() if v == 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. Yes, if `==` was replaced by `is`. Currently it is even more random as it would return the first one which evaluates __eq__() positively. That's exactly why I started this. This was to illustrate that I could not find any robust way to do it. DG.
_______________________________________________ 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/O4UIFJQ7IYR2UZWYLNAQOOXQFJJNRXVT/ Code of Conduct: http://python.org/psf/codeofconduct/