I'm using the fantastic varname python package https://pypi.org/project/varname/ to print python var names from inside the code:
>>> from varname import nameof >>> myvar = 42 >>> print(f'{nameof(myvar)} + 8: {myvar + 8}') myvar + 8: 50 >>> but when I try to use it in a loop:
>>> a, b, c, d = '', '', '', '' >>> for i in (a, b, c, d): print(f'{nameof(i)}') i i i i >>> I do not get to print a, b, c, ...
How could I get something like this ?:
a b c d
ihappened to be the name that was shown. The whole concept ofnameof()is flawed; it simply does not reflect how Python actually works.