Re: scalar vs array and program control
On Sat, 25 Jul 2015 14:44:43 +0200, Laura Creighton wrote: > And because I was rushed and posted without revision I left out > something important. >> So this is, quite likely, the pattern that you are looking for: >> try: all_your_code_which_is_happy_with_non_scalars except >> WhateverErrorPythonGivesYouWhenYouTryThisWithScalars: >> whatever_you_want_to_do_when_this_happens >> This is the usual way to do things. > I forgot to tell you that you are supposed to stick the try/except > around the smallest chunk of code that you expect to get the > exception. > So you write this as > code_you_expect_always_to_work more_code_you_expect_always_to_work > try: these_four_lines_of_code_that_will_be_unhappy_if_its_a_scalar > except ValueError: # whatever kind of error the real error is > whatever_you_want_to_do_when_that_happens > The reason is that if you get any Value Errors in the part of the code > you always expect to work, then you don't want your program to run > happily along running the code for 'its a scalar'. You don't want to > hide real errors here. > The other thing I forgot to mention is that sometimes you don't want > to do anything but ignore any errors of this sort. > Thats written like this: > code_you_expect_always_to_work more_code_you_expect_always_to_work > try: these_four_lines_of_code_that_will_be_unhappy_if_its_a_scalar > except ValueError: pass # just ignore it Thanks so much for all the pointers, and especially how `try` is used in practice. Avoiding the tangle of checks for kind of input is precisely what my intuition was telling me. -- Seb -- https://mail.python.org/mailman/listinfo/python-list
Re: Gmail eats Python
On Sat, 25 Jul 2015 18:34:30 +0200, Laura Creighton wrote: > Gmail eats Python. We just saw this mail back from Sebastian Luque > which says in part: try: all_your_code_which_is_happy_with_non_scalars except WhateverErrorPythonGivesYouWhenYouTryThisWithScalars: whatever_you_want_to_do_when_this_happens > Ow! Gmail is understanding the >>> I stuck in as 'this is from the > python console as a quoting marker and thinks it can reflow that. > I think that splunqe must already have gmail set for plain text or > else even worse mangling must show up. > How do you teach gmail not to reflow what it thinks of as 'other > people's quoted text'? Apologies for all the concern the formatting of the quoted message in my reply has generated. I actually cannot see the multiple ">" you quote here on my original follow-up message. I can tell you I'm using Emacs Gnus, and when viewing my un-processed message, that snippet looks like this: >> try: all_your_code_which_is_happy_with_non_scalars except >> WhateverErrorPythonGivesYouWhenYouTryThisWithScalars: >> whatever_you_want_to_do_when_this_happens Sure, the reflowing is probably a feature I've set up to wrap long lines. I know it annoys some people (mildly myself, as I haven't found a fix), but when reading coding fora, I never really take quoted code snippets seriously and always check the original post for these... -- Seb -- https://mail.python.org/mailman/listinfo/python-list