bag.spreadsheet package

Module contents

Spreadsheet importers in CSV and Excel formats.

The basic premise is that the spreadsheet to be imported will have headers on the first row – some of which are mandatory.

The headers are used to map the data to a dynamically-generated class so each spreadsheet row is seen, in your code, as an object (mapping columns to their values).

The code in this __init__ module is used in the inner modules.

exception bag.spreadsheet.ForbiddenHeaders(forbidden_headers)[source]

Bases: Exception

msg1 = 'The spreadsheet contains the forbidden header: '
msg2 = 'The spreadsheet contains the forbidden headers: '
exception bag.spreadsheet.MissingHeaders(missing_headers)[source]

Bases: Exception

msg1 = 'The spreadsheet is missing the required header: '
msg2 = 'The spreadsheet is missing the required headers: '
bag.spreadsheet.get_corresponding_variable_names(headers, required_headers, case_sensitive=False)[source]

Return variable names corresponding to the legible headers.

The parameter required_headers may be a map or a sequence. If map, the keys should be the legible header names and the values should be the corresponding variable names. For headers absent from the map, or if required_headers is a list, the variable names returned are the result of string conversion.

bag.spreadsheet.raise_if_forbidden_headers(headers, forbidden_headers=[], case_sensitive=False)[source]

Ensure all forbidden_headers are not present in headers.

Else raise ForbiddenHeaders.

bag.spreadsheet.raise_if_missing_required_headers(headers, required_headers=[], case_sensitive=False)[source]

Ensure all required_headers are present in headers.

Else raise MissingHeaders.