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 Dates and Times in Python (2014) Let's Build a Timed Quiz App Timestamp Ordering

Jonathan Shedd
Jonathan Shedd
1,921 Points

Don't know what's wrong with this code involving fromtimestamp()

I keep getting the error: "NoneType is not subscriptable". Not sure exactly what this means. If anyone could explain what is wrong with my code that would be a huge help! Thanks!

timestamp.py
# If you need help, look up datetime.datetime.fromtimestamp()
# Also, remember that you *will not* know how many timestamps
# are coming in.
import datetime 

def timestamp_oldest(*args):
    my_list_of_stamps = list(args)
    my_list_of_stamps = my_list_of_stamps.sort()
    return(datetime.datetime.fromtimestamp(my_list_of_stamps[0]))

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: The sort method does not return a value.

So the value your variable gets from the assignment is None, and then trying to get the "[0]" element from None produces that error.

But the sort method does modify the list it is used on:

#   my_list_of_stamps = my_list_of_stamps.sort()  <- instead of this
    my_list_of_stamps.sort()                      # ...do this
Jonathan Shedd
Jonathan Shedd
1,921 Points

Thank you so much! I got it figured out now. :)

Brent Liang
Brent Liang
Courses Plus Student 2,944 Points

Thank you Steven for the answer! Helpful. And thank you Jon for asking the question!!

Right sort does not return a value, hey Thanks Mr Parker.