Would something like the following meet your need?
Yes, it would be nice if there were a b.__name__ constant.
What is "a b.__name__ constant", and how will it be useful?
As for your solution using eval, please, please, PLEASE do not encourage
newbies to write slow, insecure, dangerous code. There are enough
security holes in software without you encouraging people to create more.
* eval is slow.
* eval is dangerous.
* eval is using a 200lb sledgehammer to crack a peanut.
Any time you find yourself thinking that you want to use eval to solve a
problem, take a long, cold shower until the urge goes away.
If you have to ask why eval is dangerous, then you don't know enough
about programming to use it safely. Scrub it out of your life until you
have learned about code injection attacks, data sanitation, trusted and
untrusted input. Then you can come back to eval and use it safely and
appropriately.
Today, your "test" function using eval is used only by yourself, at the
interactive interpreter. Tomorrow, it ends up in a web application, and
random hackers in China and script-kiddies in Bulgaria now have total
control of your server. Any time you hear about some piece of malware or
some virus infecting people's systems when they look at a PDF file,
chances are high that it is a code injection attack.
To learn more, you can start here:
http://cwe.mitre.org/top25/index.html
Two of the top three most common vulnerabilities are code injection
attacks, similar to the improper use of eval.
Here is the "eval injection" vulnerability:
http://cwe.mitre.org/data/definitions/95.html
Also google on "code injection" for many more examples.