I use the following code:
import traceback
errors = open('ERROR(S).txt', 'a')
try:
execfile("testing.py", {})
except Exception:
errors.write(traceback.format_exc() + '\n')
errors.write("\n")
errors.close()
For example I might receive
Traceback (most recent call last):
File "C:\starter.py", line 87, in execute_subscripts
execfile("test.py", {})
File "test.py", line 85, in <module>
JSONDATA = json.loads(JSONDATA)
File "C:\Python27\lib\json\__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "C:\Python27\lib\json\decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python27\lib\json\decoder.py", line 383, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
How can I also make it retrieve the the data inside the variable JSONDATA
as well as this traceback?
You could just use the
logging
library and log theJSONDATA
either to stderr with alogging.StreamHandler
or to a file with alogging.FileHandler
.Example:
I would think this is the proper way to find out what went wrong. (Alternatively you could use simple
print
or if you want to go into detail usepdb
)