Python: Copying named tuples with same attributes / fields
问题 I am writing a function that takes a named tuple and must return a super set of that tuple. For example if I was to receive a named tuple like this: Person(name='Bob', age=30, gender='male') I want to return a tuple that looks like this: Person(name='Bob', age=30, gender='male', x=0) Currently I am doing this: tuple_fields = other_tuple[0]._fields tuple_fields = tuple_fields + ('x') new_tuple = namedtuple('new_tuple', tuple_fields) Which is fine, but I do not want to have to copy each field