In an appengine application, I want to build a set of all property names for a list of objects. This should be fairly straightforward:
users = security.User.all().fetch(1000)
props = set([k for k in u.properties().keys() for u in users])
However, the code above results in an error:
File "/Users/paulkorzhyk/Projects/appengine-flask-template/app/app.py", line 70, in allusers
props = set([k for k in u.properties().keys() for u in users])
UnboundLocalError: local variable 'u' referenced before assignment
After some experiments in the debugger I've noticed that adding a dummy expression fixes the code:
users = security.User.all().fetch(1000)
[u.properties().keys() for u in users]
props = set([k for k in u.properties().keys() for u in users])
This is quite counter-intuitive to me, why is original version failing in Python 2.7? and why adding a 'useless' expression in the middle fixes the problem?