Message334967
FWIW, if folks *are* checking for tuple (and I'd love to know why) then I'd recommend that they not. :) A more Pythonic (and arguably generally better) approach would be to stick tightly to what data you need and take advantage of duck-typing. When possible, try attribute access first if you expect that (e.g. namedtuple or struct seq). Otherwise try use unpacking.
For example:
```
try:
x, y = ret.x, ret.y
except AttributeError:
pass
else:
...
```
```
try:
x, y, _ = ret
except TypeError:
pass
except ValueError:
pass
else:
...
```
Either way is easier to follow than code that relies on type (and length) checking. They also have the advantage of allowing arbitrary types that fit (duck-typing). |
|
Date |
User |
Action |
Args |
2019-02-06 17:58:10 | eric.snow | set | recipients:
+ eric.snow, rhettinger, christian.heimes, benjamin.peterson, Xiang Gao |
2019-02-06 17:58:08 | eric.snow | set | messageid: <1549475889.0.0.903007147347.issue35914@roundup.psfhosted.org> |
2019-02-06 17:58:08 | eric.snow | link | issue35914 messages |
2019-02-06 17:58:08 | eric.snow | create | |
|