Re:Python idiom for taking the single item from a list
by j_baker on Monday September 27, 2010 @03:42PM
(#1733051)
I notice a lot of "shoulds" in this comment. Unfortunately, what should be and what is aren't always the same thing.
Re:Python idiom for taking the single item from a list
by jemfinch on Monday September 27, 2010 @04:38PM
(#1733308)
No doubt! But since we're on the subject of "how to make code like this better" it seems appropriate to discuss what's really wrong with the code, rather than just what sort of duct tape style guidelines we can use to patch over its flaws :)
Re:Python idiom for taking the single item from a list
by xiongchiamiov on Monday September 27, 2010 @04:54PM
(#1733371)
Very often we can't change the API (standard library or such). Should we not change our code to address the issue as best we can?
Re:Python idiom for taking the single item from a list
by swolchok on Monday September 27, 2010 @05:24PM
(#1733500)
This is Python. Subclass it and fix the problem, unless the guts are so opaque that your code would be littered with subclasses and you can't figure out an elegant, general way of fixing it (unlikely).
In reality, you shouldn't be mucking with the entries of a widget at all; you should tell the widget what to do and it should adjust its entries as necessary). Demeter's law and all.