Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python The Problem: For Loops

Andy McDonald
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

Strptime says its getting a datetime when im giving it a string

Here's the problematic section of the code: ''' import datetime

BIRTHDAYS = ( ("James", "9/8", True, 9), ("Shawna", "12/6", True, 22), ("Amaya", "28/2", False, 8), ("Kamal", "29/4", True, 19), ("Sam", "16/7", False, 22), ("Xan", "14/3", False, 34), )

another block of code exists that puts a zero at any single digit day for each birthday.

for dude in blist: splitbday = dude[1].split('/')

if len(splitbday[1]) < 2:
    cday = '0' + splitbday[1]
    newb = splitbday[0] + '/' + cday
    dude.insert(1, newb)
    blist.insert(bcount, dude)
    bcount += 1


dblist = []

for dude in blist: print(dude) dbtime = datetime.datetime.strptime(dude[1], '%d/%m') print(dude[1]) ddude = dude ddude[1] = dbtime print(ddude) dblist.append(ddude) ''' It keeps saying that strptime requires a string but when I print "dude" it is clearly a string. I dont know what to do. Doesn't seem to make sense.

Steven Parker
Steven Parker
228,991 Points

Code should be complete and properly formatted. Take a look at these videos about Posting a Question, using Markdown formatting to preserve the code's appearance, and particularly this one about sharing a snapshot of your workspace.

1 Answer

If "dude" is a string, then "dude[1]" would be a single character which wouldn't match the date time formatting, right?