MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/28utww/writing_better_python_code/ciesq6f/?context=3
r/Python • u/kracekumar • Jun 23 '14
126 comments sorted by
View all comments
46
I have problems with some of these.
Replacing a or b or c by any([a, b, c]). Is that really more Pythonic? If they'd been in an iterable already I'd say yes, but now not so much.
a or b or c
any([a, b, c])
Catching KeyError just to raise another KeyError? Just let it bubble up.
KeyError
I kinda hate namedtuple because it's such a hack, but maybe that's just me.
namedtuple
Also, I'd say the opposite of Pythonic code is not normal code. Un-Pythonic or unidiomatic, or maybe something about newbies.
12 u/ivosaurus pip'ing it up Jun 23 '14 edited Jun 23 '14 Agreed, using all and any over and and or isn't more pythonic at all. Use all and any when you already have a list / iterable, it's what they're designed for. 1 u/iBlag Jun 23 '14 Do you mean:using all and anyandUse all and any? 2 u/ivosaurus pip'ing it up Jun 23 '14 Yeah.
12
Agreed, using all and any over and and or isn't more pythonic at all. Use all and any when you already have a list / iterable, it's what they're designed for.
all
any
and
or
1 u/iBlag Jun 23 '14 Do you mean:using all and anyandUse all and any? 2 u/ivosaurus pip'ing it up Jun 23 '14 Yeah.
1
Do you mean:
using all and any
Use all and any
?
2 u/ivosaurus pip'ing it up Jun 23 '14 Yeah.
2
Yeah.
46
u/robin-gvx Jun 23 '14
I have problems with some of these.
Replacing
a or b or cbyany([a, b, c]). Is that really more Pythonic? If they'd been in an iterable already I'd say yes, but now not so much.Catching
KeyErrorjust to raise anotherKeyError? Just let it bubble up.I kinda hate
namedtuplebecause it's such a hack, but maybe that's just me.Also, I'd say the opposite of Pythonic code is not normal code. Un-Pythonic or unidiomatic, or maybe something about newbies.