Created
March 24, 2014 10:14
-
-
Save onjin/9737643 to your computer and use it in GitHub Desktop.
tuple to namedtuple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
# magic data accessed with magic numbers, f.i.: | |
# print "{} {}".format(row[2], row[3]) | |
row = ('SS', 'asdf', 12.3, 'USD') | |
# let's create something self describing | |
Price = namedtuple('Price', ['symbol', 'name', 'amount', 'currency']) | |
# fill it from previous tuple | |
price = Price(*row) | |
# use it with joy | |
print "{} {}".format(price.amount, price.currency) | |
print price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment