명명 된 튜플을 취하여 해당 튜플의 슈퍼 세트를 반환해야하는 함수를 작성했습니다. 현재Python : 동일한 속성/필드를 가진 명명 된 튜플 복사하기
Person(name='Bob', age=30, gender='male', x=0)
내가이 일을하고있다 :
Person(name='Bob', age=30, gender='male')
내가 다음과 같습니다 튜플을 반환하려면 :
예를 들어 는이 같은 명명 된 튜플을받을 수 있다면tuple_fields = other_tuple[0]._fields
tuple_fields = tuple_fields + ('x')
new_tuple = namedtuple('new_tuple', tuple_fields)
어느 것이 좋지만 다음과 같이 각 필드를 복사하고 싶지는 않습니다.
tuple = new_tuple(name=other_tuple.name,
age=other_tuple.age,
gender=other_tuple.gender,
x=0)
FIRST 개체의 각 개체를 반복하고 그 개체를 복사 할 수 있기를 바랍니다. 실제 튜플은 30 개 필드입니다.
가능한 중복 : //stackoverflow.com/questions/39098452/inherit-namedtuple-from-a-base-class-in-python) –