python - Creating a namedtuple from a list -




consider list variable t

in [55]: t out[55]: ['1.423',  '0.046',  '98.521',  '0.010',  '0.000',  '0.000',  '5814251520.0',  '769945600.0',  '18775908352.0',  '2.45024350208e+11',  '8131.903',  '168485.073',  '0.0',  '0.0',  '0.022',  '372.162',  '1123.041',  '1448.424'] 

now consider namedtuple 'point':

point = namedtuple('point', 'usr sys idl wai hiq siq  used  buff  cach  free     read  writ recv  send majpf minpf alloc  vmfree') 

how convert variable t point? obvious (to me anyways..) approach - of providing list constructor argument - not work:

in [57]: point(t) --------------------------------------------------------------------------- typeerror                                 traceback (most recent call last) <ipython-input-57-635019d8b551> in <module>() ----> 1 point(t)  typeerror: __new__() takes 19 arguments (2 given) 

use point(*t) expand contents of t arguments point constructor.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -