``` # Why Python is Great: Namedtuples # Using namedtuple is way shorter than # defining a class manually: >>> from collections import namedtuple >>> Car = namedtuple('Car', 'color mileage') # Our new "Car" class works as expected: >>> my_car = Car('red', 3812.4) >>> my_car.color 'red' >>> my_car.mileage 3812.4 # We get a nice string repr for free: >>> my_car Car(color='red' , mileage=3812.4) # Like tuples, namedtuples are immutable: >>> my_car.color = 'blue' AttributeError: "can't set attribute" ```
post_id | 73,523,345 |
---|---|
author | boyanpro |
permlink | python-tricks-5-namedtuples |
category | programming |
json_metadata | {"community":"busy","app":"partiko","format":"markdown","tags":["programming","python","pytricks","coding","dev","partiko"],"users":[],"links":[]} |
created | 2019-04-22 07:03:24 |
last_update | 2019-04-22 07:25:42 |
depth | 0 |
children | 0 |
net_rshares | 1,062,762,320,758 |
last_payout | 2019-04-29 07:03:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.408 SBD |
curator_payout_value | 0.116 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 508 |
author_reputation | 1,773,735,625,367 |
root_title | "Python Tricks #6 - Namedtuples" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
kaylinart | 0 | 150,200,892,440 | 73% | ||
claudiop63 | 0 | 6,177,392,636 | 100% | ||
najoh | 0 | 7,296,755,010 | 100% | ||
achim86 | 0 | 9,108,342,396 | 100% | ||
eforucom | 0 | 15,366,165,329 | 2% | ||
shikika | 0 | 135,360,210,955 | 100% | ||
leontr | 0 | 20,674,068,836 | 100% | ||
mufasatoldyou | 0 | 5,975,328,331 | 100% | ||
kamilason | 0 | 7,136,651,632 | 100% | ||
foruni73 | 0 | 60,077,076,085 | 100% | ||
tipu | 0 | 454,824,034,710 | 0.72% | ||
hannesl | 0 | 5,852,268,640 | 100% | ||
attoan.cmt | 0 | 17,129,190,448 | 100% | ||
cnsteem | 0 | 8,018,714,242 | 100% | ||
vdux | 0 | 8,835,519,306 | 100% | ||
r351574nc3 | 0 | 7,296,852,212 | 100% | ||
kentzz001 | 0 | 6,380,618,630 | 100% | ||
coffeebreak | 0 | 6,119,621,880 | 100% | ||
badmusgreene | 0 | 18,962,919,640 | 100% | ||
nanobot | 0 | 370,940,636 | 5% | ||
steemhelpinghand | 0 | 13,930,041,546 | 100% | ||
salty-mcgriddles | 0 | 7,008,623,277 | 100% | ||
nassifelias | 0 | 9,317,998,999 | 100% | ||
boyanpro | 0 | 29,399,984,189 | 100% | ||
minminlou | 0 | 74,467,278 | 1% | ||
mariita52 | 0 | 1,188,577,863 | 100% | ||
kamo.munshi | 0 | 4,780,089,014 | 100% | ||
healthybrain | 0 | 5,786,186,959 | 100% | ||
kardiva | 0 | 2,290,186,695 | 100% | ||
supu | 0 | 15,089,954,976 | 2% | ||
smolechka | 0 | 6,660,942,131 | 100% | ||
merlin4 | 0 | 7,809,698,831 | 100% | ||
edishint | 0 | 501,757,697 | 100% | ||
nouno | 0 | 501,786,095 | 100% | ||
zugs | 0 | 7,258,461,214 | 2% |