You want the condition to be evaluated at each iteration through the loop at the end, for example:
s = ''.join('%s: %s </br>' %
(a,getattr(user, a)) for a in dir(user) if '__' not in a
)
Edit: Sorry, copy the brackets to the appropriate attachment.
Edited: Condition changed (didn’t even pay attention to it, thanks Falmarri.
source
share