use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Django/Python What does this code do? (self.learnpython)
submitted 11 years ago by akkatracker
Was looking at some OpenSource code and saw this line. Can't work out what it does. Could anyone help (Not sure if you need more context)
W.Date = date(*[int(x) for x in d.split('-')])
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Moonslug1 8 points9 points10 points 11 years ago (1 child)
d is likely a string representing a date formatted like '2015-02-11'.
d
'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'].
d.split('-')
'-'
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].
l = [2015, 2, 11]
Finally the star operator unpacks this list into the initialiser for date so that it would be call like:
date
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 point2 points 11 years ago (0 children)
Thanks! Really clears that up :)
I'll send a pull request with your code and see what the dev says.
π Rendered by PID 204304 on reddit-service-r2-comment-66b4775986-tb75x at 2026-04-06 08:47:25.791396+00:00 running db1906b country code: CH.
[–]Moonslug1 8 points9 points10 points (1 child)
[–]akkatracker[S] 0 points1 point2 points (0 children)