I've got some code which does:
try:
result = func()
except StandardError as e:
result = e
How can I check whether result contains an Exception?
Using isinstance(result, Exception) doesn't work as exceptions are a class, not an instance, e.g. type(ValueError) gives <type 'type'>.
--- Edit ---
Well that was stupid; while the above code was a correct distillation of how I was using func(), what my test func() was doing was return ValueError, not raise ValueError. With the former returning the class and the latter returning an instance. So the problem wasn't as described.
isinstance(result, Exception)? works for me sinceeis an instance ofStandardErrornot the classStandardErroritself.result=Noneand use a different name, egerr = efor the error. Then you can easily know if you have an error or a result: iferr is Nonethen no error and result is good otherwise you have an error.