Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/stakx.py
Last active December 16, 2015 04:49
Show Gist options
  • Select an option

  • Save zeffii/5380395 to your computer and use it in GitHub Desktop.

Select an option

Save zeffii/5380395 to your computer and use it in GitHub Desktop.
# stakx.py
import collections
strs = ['one', 'two', 'three', 'four']
values = 1, 2, 3, 4
originals = dict(zip(strs, values))
file_params = collections.namedtuple('file_params', 'one two three four')
rfile_params = file_params(**originals)
print(rfile_params.one)
print(rfile_params.two)
print(rfile_params.three)
print(rfile_params.four)
@arne-cl

arne-cl commented Jul 24, 2014

Copy link
Copy Markdown

namedtuple has a ._make method, which takes an iterable as input:

>>> file_params._make(values)
file_params(one=1, two=2, three=3, four=4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment