2018-05-23 6:32 GMT+09:00 Kirill Balunov <kirillbalu...@gmail.com>: > Just one more variation on "assignment exression" syntax to make the list > more complete :) Sorry, if something similar has already been suggested. > The idea is to use function's call-like syntax in the from: `this( name = > expr )`. I'm not sure that such idea will find its supporters and whether > it is possible to implement it in a general way, but nevertheless. Below is > a half- and slow-working prototype and some silly examples just for the > sake of feeling the idea: > > import sys > import ctypes > > def this(**assign): > assert len(assign) == 1 > [(name, value)] = assign.items() > frame = sys._getframe(1) > frame.f_locals[name] = value > ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame), > ctypes.c_int(0)) > return value > > FYI, I found a package [*] which binds a value by function keyword (I'm not the author). Note that the package writes a value in the global (or raise an error if the name already exists in local) unlike your idea.
[*] https://pypi.org/project/let3/ -- Masayuki
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/