What, if anything, is wrong with this line of python code:
daterange = [begin + timedelta(n) for n in range((end - begin).days)]
Where begin
and end
are datetime.date
objects with valid values.
I'm using this in a Django view to process some data, but everytime the view this is in gets called I get the following error with the aforementioned line highlighted:
UnboundLocalError at /url/of/error/creating/view/here/
local variable 'range' referenced before assignment
If I execute this line inside the interpreter it works fine, but somehow it doesn't fly inside a Django view. I don't understand why range
is being interpreted as a variable name at all. Is there actually something wrong with this line, or is it something else in the code that's making Django complain?
Help!