While looking for some answers in a package source code (colander to be specific) I stumbled upon a string that I cannot comprehend. Also my PyCharm frowns on it with 'statement seems to have no effect'.
Here's the code abstract:
...
for path in e.paths():
keyparts = []
msgs = []
for exc in path:
exc.msg and msgs.extend(exc.messages()) # <-- what is that?
keyname = exc._keyname()
keyname and keyparts.append(keyname) # <-- and that
errors['.'.join(keyparts)] = '; '.join(interpolate(msgs))
return errors
...
It seems to be extremely pythonic and I want to master it!
UPD. So, as I see it's not pythonic at all - readability is harmed for the sake of shorthand.
and
andor
work it's not a reflection on its Pythonicness. Usingand
as a guard is very Pythonic.and
andor
work in Python, but I've never been a fan of using stuff like that in this kind of way. It has the potential for bugs and is harder to read. Using anif
statement is always a better solution.always
, asalways
rarely is. ;)