Clayton Clayton - 9 months ago 62
Python Question

Creating namedtuple instance from already set values

I have a

like this

course_summary_struct = namedtuple(
['id', 'display_name', 'location', 'display_coursenum', 'display_organization']

I want to update the the
dynamically until I am sure it has all required information.

So i Update
with all the values in steps.

Now I am at a place where I need to create an instance from
like this

summery = course_summary_struct() #<===== Issue here

I want to fill
with all the information in

How can I do that?

Answer Source

Wait until you have all the necessary information before actually creating the named tuple instance.

data = {}
data['id'] = 3
# ...
data['display_name'] = 'Chem 101'
# ...
summary = course_summary_struct._make([data[x] for x in course_summary_struct._fields])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download