python - Is it posible to return on the line with exception? -
I have a code that looks like this:
try: a = Try: Pass [a '] except: [B]: B = form [' B '] except keyError: try the following: c = form [' c '] except keyError: try: D = form [ D] except keyError: pass
is something capable of doing something:
try: a = form ['a'] b = form ['b '] C = form [' c '] d = form [' d '] except keyError: some keywords
So if any' a 'form is still working in the form Au Key 'B' and so on
UPD: Sorry, my bad, I do not need to preserve the values, and not one of them. That's why I need a keyword or something that will help me to continue the block even after the exception raises.
If the form
is a dictionary then you can also use syntax Are:
& gt; & Gt; & Gt; Form = {'D': 5}> & gt; & Gt; 5)
You can create the function. Format ('a', form.get ('b', form.get ('c', form ['d'])) 5
using some iterators Lazy call:
>
edit : if you need all:
> gt;> A , B, c, d = map (form.get, ['a', 'b', 'c', 'd']) and gt; & gt; a, b, c, d (none , None, none, 5)
Comments
Post a Comment