When using ctypes with libraries I'm not familiar with (in this specific case, Windows API), I tend to be really aggressive with checking each little step for failures since the Windows API simply returns Null, rather than throwing any kind of error.
So, I have tons of lines that look like this:
myVariableName = windll.user32.SomeWinAPIFuncThatReturnsZeroIfItFails()
if not myVariableName: print "Failed to create myVariableName"
And I repeat that a kazzilion times while figuring out the code.
It would be really nice if I could wrap the above check into a checkSuccess()
function, which would simply take the name of the variable to check.
Something along the lines of
def check_success(var_name):
if not var_name:
print "failed to create %s" % var_name # <-- but the actual variable name; not the value
sys.exit()
return True
Of course, I could just manually pass in a string of the variable name, but for cleanliness and boilerplate's sake, it'd be cool it I could just pass in the single variable name.
Hopefully that makes sense!