1.6 Advanced functions
1.6.1 merge method
The method unifies two bags. merge() has four optional parameters:
| flag | default |
| upd_values | True |
| add_values | True |
| upd_attr | True |
| add_attr | True |
john_doe=Bag()
john_doe['telephones']=Bag()
john_doe['telephones.house']=55523412
other_numbers=Bag({'mobile':444334523, 'office':3320924, 'house':2929387})
other_numbers.setAttr('office',{'from': 9, 'to':17})
john_doe['telephones']=john_doe['telephones'].merge(other_numbers)
>>> print john_doe
0 - (Bag) telephones:
0 - (int) house: 2929387
1 - (int) mobile: 444334523
2 - (int) office: 3320924 <to='17' from='9'>
john_doe['credit_cards']=Bag()
As you can see, since I did't set any of the flag parameters to False merge added twe new values (mobile, office), updated a value (house) and added two attributes.
