[Python-ideas] Implied try blocks

Masklinn masklinn at masklinn.net
Sun Mar 25 17:32:22 CEST 2012


On 2012年03月25日, at 17:19 , Antoine Pitrou wrote:
> On 2012年3月25日 10:15:05 -0400
> Calvin Spealman <ironfroggy at gmail.com>
> wrote:
>>>> What if we allowed this to be implied and except/else blocks bound to
>> the previous
>> statement? A try block would be an optional form, and mostly left for
>> multi-block try's
>>>> r = some_single_statement()
>> except TypeError:
>> print "oh no!"
>> raise OhNoException()
>> else:
>> p = prepare(r)
>> print "I got", p
>> Saving one line and four non-whitespace characters?
> -1 from me.

Just the characters, since the single statement could be put on the same line as the try:
 try: r = some_single_statement()
 except TypeError:
 print "oh no!"
 raise OhNoException()
 p = prepare(r)
 print "I got", p


More information about the Python-ideas mailing list

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