Message279623
The syntax is working correctly. Precedence rules are throwing you off. It should be more clear if we use parentheses to demonstrate precedence explicitly.
You expected:
a, b = (obj.a, obj.b) if obj else [None, None]
However, what you wrote is equivalent to:
a, b = obj.a, (obj.b if obj else [None, None])
Hence the error about not finding "None.a" (when it resolves obj.a). You can solve this by explicitly marking the precedence like I did in the "You expected" example above. Sometimes precedence isn't clear, so when in doubt, use parentheses to make the precedence explicit.
I'm sorry this wasn't more clear. Do you think any changes in Python's documentation would have helped you avoid this confusion? |
|
Date |
User |
Action |
Args |
2016-10-28 18:25:45 | eric.snow | set | recipients:
+ eric.snow, levinvm |
2016-10-28 18:25:45 | eric.snow | set | messageid: <1477679145.49.0.969064240435.issue28550@psf.upfronthosting.co.za> |
2016-10-28 18:25:45 | eric.snow | link | issue28550 messages |
2016-10-28 18:25:45 | eric.snow | create | |
|