Profiling code is important. In python, the easiest way to time your code is to do the following: from datetime import datetime start = datetime.now() # Some long-running process end = datetime.now() print "process run in %s" % (end – start) This solution works, but it can be annoying to write, and you’ll have to [...]
Category Archives: python
Easy Handling of Python datetimes in JSON.
Passing date objects between Python and Javascript can be difficult. I started using this as a workaround to handle python’s datetime objects, but it should work for any non-standard, non-primitive python type: import time, math def dt_handler(obj): if isinstance(obj, datetime) or isinstance(obj, date): v = math.floor(time.mktime(obj.timetuple())) return "DATE(%d)" % v else: return repr(obj) Instead of [...]
Posted in python Leave a comment