On Tue, 19 May 2009, Gökhan SEVER wrote: > Hello, > > Could you please explain why locals() allow me to create variables that are > not legal in Python syntax. Example: locals()['1abc'] = 55. Calling of 1abc > results with a syntax error. Shouldn't it be better to raise an error > during the variable creation time? >
The docs warn against modifying locals() because for one thing, the interpreter may not know about the changes you make. You can add any item to the locals() dictionary without causing an error, but that doesn't necessarily mean you have created a legal object and named it. But admittedly that doesn't actually answer your question. :) Regards, John -- http://mail.python.org/mailman/listinfo/python-list