Skip to content

Conversation

@DeepSpace2
Copy link

@DeepSpace2 DeepSpace2 commented Apr 8, 2020

Hi all.

Before I start, I'm aware of #224 but it is 4 years old and tablib has changed quite extensively since then (dropped Python 2 support, format extensions are now classes, etc) so I thought I'd have a go at it.

It's a WIP and only supports export of dataset, but it supports tags.

The dataset

data = Dataset(headers=['first_name', 'last_name', 'gpa'])
data.append(('John', 'Adams', 90))
data.append(('George', 'Washington', 67), tags=['tag 1', 'tag 2'])

is exported as

<dataset>
    <row>
        <first_name>John</first_name>
        <last_name>Adams</last_name>
        <gpa>90</gpa>
    </row>
    <row tags="tag 1,tag 2">
        <first_name>George</first_name>
        <last_name>Washington</last_name>
        <gpa>67</gpa>
    </row>
</dataset>

I do have a question: Is there a proper way to access a row's tags while iterating over the dataset? The only way I found is to use enumerate and then use the row's index to index into _data which of course if unfavorable.

for row_index, row in enumerate(dataset.dict):
    tags = dataset._data[row_index].tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant