yokome.util.persistence
¶
-
yokome.util.persistence.
list_as_tuple_hook
(x)¶ Transform all list entries in a dictionary into tuples.
This function can be used to load JSON files with tuples instead of lists.
- Parameters
x (dict) – A dictionary.
- Returns
The input dictionary, with lists transformed into tuples.
-
yokome.util.persistence.
quote
(value)¶ Quote a value unambigously w.r.t. its data type.
The result can be used during import into a relational database.
- Parameters
value – The value to transform.
- Returns
'null'
ifvalue
isNone
,'true'
if it isTrue
,'false' if it is ``False
. For numeric values, the result is the corresponding string representation. Infinite values are represented by'inf'
and'-inf'
, respectively; not-a-number is represented by'nan'
. For strings, the result is the string itself, surrounded by'"'
, and with the characters'"'
,'\'
,'\b'
,'\t'
,'\n'
,'\v'
,'\f'
and'\r'
escaped using'\'
.- Raises
TypeError – If
value
is neitherNone
nor of typebool
,int
,float
orstr
.
-
yokome.util.persistence.
write_quoted
(file, row)¶ Write a row of quoted CSV values to a file.
The values in
row
are quoted so that their data type can be detected unambiguously (seeyokome.util.persistence.quote()
for a detailed explanation). Furthermore, they are separated by the character','
. Lines are separated with'\n'
.- Parameters
file – The file to write to. It has to be open.
row – An iterable of data values.