Confused compare function :)
Rotwang
sg552 at hotmail.co.uk
Wed Dec 5 22:22:53 EST 2012
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?
--
I have made a thing that superficially resembles music:
http://soundcloud.com/eroneity/we-berated-our-own-crapiness
More information about the Python-list
mailing list