Letter replacer - suggestions?

Chris Angelico rosuav at gmail.com
Mon Dec 7 14:53:07 EST 2020


On Tue, Dec 8, 2020 at 6:41 AM Grant Edwards <grant.b.edwards at gmail.com> wrote:
>> On 2020年12月07日, MRAB <python at mrabarnett.plus.com> wrote:
>> > Avoid a 'bare' except unless you _really_ mean it, which is
> > virtually never. Catch only those exceptions that you're going to
> > handle.
>> And sometimes "handling" is just printing some extra stuff and then
> re-raising the original exception:
>> try:
> something():
> except:
> print(<whatever might be helpful for troubleshooting>)
> raise
>
Even there, I'd most often use "except BaseException as e:", other
than in a very few situations. The only time I have recently used a
bare except is when making use of the traceback module:
try:
 ...
except:
 with open("notes.err", "a") as err:
 traceback.print_exc(file=err)
 raise
since print_exc() can go fetch the exception via sys.exc_info().
ChrisA


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /