* Steven D'Aprano <st...@pearwood.info> [110103 15:03]: > Tim Johnson wrote: >> I'm just have a little fun here, but I bet that comments will help >> further elighten me on the subtleties of python. >> >> consider the following console session: >>>>> L = ['foo','bar'] >>>>> locals()[L[0]] = L[1] > > This will not do what you think it does. In general, local variables are > not writable except the normal way by `name = value` assignment. Try > this function: > > def spam(): > x = 1 > print(x) > locals()['x'] = 2 > print(x) > > > The fact that assignment to locals() works in the top-level global scope > is an accident of implementation. :) thanks for doing my homework for me. > > Have you considered using the ConfigParser module? Good tip. I will look at it
> (1) This won't work except in the global scope. > > (2) Even if it did work, do you trust the source of the text? Taking > external data provided by arbitrary untrusted users and turning it into > variables is a good way to have your computer owned by bad guys. Say what? I'm not talking about anything accessible by "arbitrary users". Sorry if I gave that impression! Thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor