View Single Post
Old Feb 12th, 2007, 6:22 PM   #5
poopman
Newbie
 
Join Date: Feb 2007
Posts: 13
Rep Power: 0 poopman is on a distinguished road
Quote:
Originally Posted by Arevos View Post
If you want to access an element of a tuple, you can use indices, in the same way you would an array or list:
python Syntax (Toggle Plain Text)
  1. result = (datetime.date(2007, 2, 9),)
  2. date = result[0]
  3. print date.strftime("%Y-%m-%d")
Or simply:
python Syntax (Toggle Plain Text)
  1. print result[0].strftime("%Y-%m-%d")
You can also assign a tuple to an set of variables to get its contents:
python Syntax (Toggle Plain Text)
  1. coords = (4, 6)
  2. x, y = coords
And for a tuple with a single value:
python Syntax (Toggle Plain Text)
  1. result = (datetime.date(2007, 2, 9),)
  2. date, = result
This notation when applied to only one value is a little obscure, however.
Thanks for this. I tried out all these methods and kept coming up with this error:

AttributeError: 'tuple' object has no attribute 'strftime'

I can't figure out why this isn't working as it seems pretty straightfoward.
poopman is offline   Reply With Quote