Bases: lib.listData.DataTuple
Returns the cell value specified by the row and column index.
Parameters: |
|
---|---|
Returns: | cell value |
>>> data = DataDict([{'id': 0, 'hello':'world'},
... {'id': 1, 'foo':'bar'}])
>>> data.get_headers()
['foo', 'hello', 'id']
>>> data.get(0,0)
''
>>> data.get(0,1)
'world'
>>> data.get(1,0)
'bar'
>>> data.get(1,1)
''
>>> data.get(1,2)
1
Returns the cell value specified by the row and column header.
Parameters: |
|
---|---|
Returns: | cell value |
>>> data = DataDict([{'id': 0, 'hello':'world'},
... {'id': 1, 'foo':'bar'}], headers=['foo','hello'])
>>> data.get_by_header(0,'foo')
''
>>> data.get_by_header(0,'hello')
'world'
>>> data.get_by_header(1,'foo')
'bar'
Get the headers of the columns.
Returns: | headers of the columns |
---|---|
Return type: | list of strings |
>>> data = DataDict([{'id': 0, 'hello':'world'},
... {'id': 1, 'foo':'bar', 'hello':'planet'}])
>>> data.get_headers()
['foo', 'hello', 'id']
Sorts the data in place.
>>> DataDict(id='path').sort([{'path': 'id1', 'name': 'f1'},
... {'path': 'id0', 'name': 'f2'}])
[{'path': 'id0', 'name': 'f2'}, {'path': 'id1', 'name': 'f1'}]
Change sequence and find all headers (dict keys) in the data.
>>> data = DataDict([{'id': 0, 'hello':'world'},
... {'id': 1, 'foo':'bar'}])
>>> data.get_headers()
['foo', 'hello', 'id']
>>> data.update_headers(['hello'])
>>> data.get_headers()
['hello']
>>> data.update_headers(['hello'], all=True)
>>> data._headers
['hello', 'foo', 'id']
Bases: object
Returns the cell value specified by the row and col.
Parameters: |
|
---|---|
Returns: | cell value |
>>> data = DataTuple([(0, 6)])
>>> data.get(0,0)
6
Get the headers of the columns.
Returns: | headers of the columns |
---|---|
Return type: | list of strings |
>>> data = DataTuple([('id1','f1'),('id0','f2')])
>>> data.get_headers()
['0']
The data is organised as tuple/list of tuples. Amount is how much is visible and not necessarily the length of the data tuple!
Parameters: |
|
---|---|
Returns: | whether the underlying data has really changed |
Return type: | bool |
>>> data = DataTuple()
>>> data.set_data([(6, ),(5, )], amount=1)
True
>>> data.set_data([(6, ),(5, )], amount=1)
False
>>> len(data) == data.amount
False
Filters the data which is visible. It puts the visible data rows to the front and limits the amount. The visible data is automatically sorted.
Parameter: | filter (string) – substring which should appear in the data rows |
---|---|
Returns: | whether the filter has really changed |
Return type: | bool |
>>> data = DataTuple([(6, ),(5, )])
>>> data.set_filter('6')
True
>>> data.set_filter('6')
False
>>> data.amount
1
>>> len(data)
2
Sorts the data in place.
>>> DataTuple().sort([('id1','f1'),('id0','f2')])
[('id0', 'f2'), ('id1', 'f1')]
Turns a flat file list into a hierarchical one , of which the data values can be fed to the DataDict Class (not the whole hierarchy).
Parameter: | files (list) – rows which consists of tuples, each tuples contains the full filename as the first element before other data |
---|---|
Returns: | folder hierarchy |
Return type: | dict |
>>> import pprint
>>> files = [{'path': 'f0/i00', 'size': '5kb'},
... {'path': 'f0/i01', 'size': '1kb'},
... {'path': 'f1/i10', 'size': '2kb'},
... {'path': 'f1/f2/i120', 'size': '3kb'}]
>>> pprint.pprint(files_data_dict(files),width=60)
{'f0/': {'children': {},
'data': [{'path': 'f0/i00', 'size': '5kb'},
{'path': 'f0/i01', 'size': '1kb'}]},
'f1/': {'children': {},
'data': [{'path': 'f1/i10', 'size': '2kb'}]},
'f1/f2/': {'children': {},
'data': [{'path': 'f1/f2/i120',
'size': '3kb'}]}}
Turns a flat file list into a hierarchical one, of which the data values can be fed to the DataTuple Class (not the whole hierarchy).
Parameter: | files (list) – rows which consists of tuples, each tuples contains the full filename as the first element before other data |
---|---|
Returns: | folder hierarchy |
Return type: | dict |
>>> import pprint
>>> files = [('f0/i00', 0), ('f0/i01', 1),
... ('f1/i10', 2), ('f1/f2/i120', 3),]
>>> pprint.pprint(files_data_tuple(files),width=60)
{'f0/': {'children': {},
'data': [('f0/i00', 0), ('f0/i01', 1)]},
'f1/': {'children': {}, 'data': [('f1/i10', 2)]},
'f1/f2/': {'children': {}, 'data': [('f1/f2/i120', 3)]}}