New issue 2466: request for the capability of updating local variable list using locals().update() https://bitbucket.org/pypy/pypy/issues/2466/request-for-the-capability-of-updating
Wang Xuancong: The ability of updating local variable name list becomes important and useful when we talk about meta-programming. For example, we can use the following line to save and load all local variables instead of importing json and writing down every variable we want to save/load: ``` print >>open('model.txt','w'), locals() locals().update(eval(open('model.txt').read())) ``` This functionality is particularly useful in designing neural networks using Tensorflow/Theano/etc. We can snapshot/restore all local variables so that we can continue to work on from somewhere else. However, due to interpreter optimization, python is not designed to do this: [https://docs.python.org/2/library/functions.html#locals](Link URL), the same holds for PyPy: ``` >>>> def f1(): .... locals().update({'aa':5}) .... print aa .... >>>> f1() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in f1 NameError: global name 'aa' is not defined ``` Since PyPy has built-in JIT, it does not need to be too concerned about interpreter optimization. Thus, I hope this functionality can be implemented in PyPy as an advantage over Python. _______________________________________________ pypy-issue mailing list pypy-issue@python.org https://mail.python.org/mailman/listinfo/pypy-issue