Adding timedelta to a datetime.time

• 2 min read
One of Python's strengths is its exhaustive library. And date and time management is an integral part of this, provided by the datetime. Logic suggests that timedelta. That is code like this would produce an error: >>> from datetime import datetime, date, time, timedelta >>> dt1 = datetime.now() >>> td1 = timedelta(hours=1 …

Convert time string to datetime.time object

• 2 min read
I'm still finding my way around the rather vast Python standard library. And today, I discovered a quick way to convert a pure time string (of format HH:MM[:SS]) into a standard datetime.time object. datetime.strptime('08:00', '%H:%M').time() That's it! A single, rather short line …


Debugging Django Template Tags

Here's a cool bit of code snippet that I found from the web (original post here). I'm recording it here for my own easy reference without having to google it all the time. It describes a simple technique to debug Django templates using the python debugger - pdb. @register.filter def …