Data types in Bags

A bag may contain as values items of any type, but Bag provides some features to coerce data types if needed. You can insert a value as string, but associate to it a different type adding to the label the special symbol '::' followed by a type code.

Type codes:

Codes Data Type
'T', 'TEXT' txt
'R', 'F', 'FLOAT', 'REAL' float
'L', 'LONG', 'LONGINT', 'I', 'INT', 'INTEGER'int
'B', 'BOOL', 'BOOLEAN'bool
'D', 'DATE' datetime
'DT', 'DATETIME'datetime
'H', 'TIME' datetime.time
'BAG' Bag
mybag['birthday::D']='1984-3-3'
mybag['age::I']='22'
>>> mybag['birthday']
datetime.date(1984, 3, 3)
>>> isinstance(mybag['age'], int)
True

This type coercion is valid also for Bag's attributes:

root=Bag()
root.setItem('header', Bag(), class='basic', text_size='')