Confused compare function :)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Dec 5 23:32:34 EST 2012
On Thu, 06 Dec 2012 03:22:53 +0000, Rotwang wrote:
> On 06/12/2012 00:19, Bruno Dupuis wrote:
>> [...]
>>
>> Another advice: never ever
>>
>> except XXXError:
>> pass
>>
>> at least log, or count, or warn, or anything, but don't pass.
>
> Really? I've used that kind of thing several times in my code. For
> example, there's a point where I have a list of strings and I want to
> create a list of those ints that are represented in string form in my
> list, so I do this:
>
> listofints = []
> for k in listofstrings:
> try:
> listofints.append(int(k))
> except ValueError:
> pass
>
> Another example: I have a dialog box with an entry field where the user
> can specify a colour by entering a string, and a preview box showing the
> colour. I want the preview to automatically update when the user has
> finished entering a valid colour string, so whenever the entry field is
> modified I call this:
>
> def preview(*args):
> try:
> previewbox.config(bg = str(entryfield.get()))
> except tk.TclError:
> pass
>
> Is there a problem with either of the above? If so, what should I do
> instead?
They're fine.
Never, ever say that people should never, ever do something.
*cough*
--
Steven
More information about the Python-list
mailing list