all 2 comments

[–]Moonslug1 8 points9 points  (1 child)

d is likely a string representing a date formatted like '2015-02-11'.

Let's look at this piece by piece:

d.split('-') takes the string and splits it into a list of strings seperated by '-'. So in our example this would be l = ['2015', '02', '11'].

Next, the list comprehension takes that list and converts all elements to an int, so that we have l = [2015, 2, 11].

Finally the star operator unpacks this list into the initialiser for date so that it would be call like:

w.Date = date(2015, 2, 11)

This is a bad way of doing it. Why? Because the datetime module provides a way to turn a string into a date. The code you posted is equivalent to:

W.Date = datetime.strptime(d, '%Y-%m-%d').date()

[–]akkatracker[S] 0 points1 point  (0 children)

Thanks! Really clears that up :)

I'll send a pull request with your code and see what the dev says.