![]() ![]() Is a wrapper function the correct approach here? If the function had worked, this would have printed "Error", right? Call a function that doesn't exist, it doesn't try-catch it away: > f(meow())īefore I even add a blank return value, I'd like to get it to try-catch correctly. Here's what I tried, with a wrapper: def f(func): My understanding is that some kind of wrapper should be able to fix this. The former would be sort of an item-wise skip - where that key isn't available, it logs blank and moves on - the latter is a row-skip, where if any of the fields don't work, the entire record is skipped. where I can wrap either the single data item (1), or a master function (2), in some function that turns execution-halting exceptions into empty fields, printed to stdout. Here's what I'd like, (1): item = f(myobject.get('key').get('subkey')) Item = FUNCTION_THAT_DOESNT_EXIST(thod()) Item = OBJECT_THAT_DOESNT_EXIST.get('key2') Item = myobject.get('key').METHOD_THAT_DOESNT_EXIST() It's more valuable, in my use-case to continue executing over the loop than to get all keys. I understand it's a bad policy to swallow exceptions, but I'd rather prefer they to be printed and analysed later, than to actually stop execution. I find myself writing involved try-except blocks, and would rather just wrap the dubious function up. I'd interacting with a lot of deeply nested json I didn't write, and would like to make my python script more 'forgiving' to invalid input. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |