Skip to content

Commit 70be784

Browse files
committed
[tools/ParserUtils] Add odml tuple export func
1 parent 9d1cb88 commit 70be784

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

odml/tools/parser_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,24 @@ class InvalidVersionException(ParserException):
3434
Exception wrapper to indicate a non-compatible odML version.
3535
"""
3636
pass
37+
38+
39+
def odml_tuple_export(odml_tuples):
40+
"""
41+
Converts odml style tuples to a parsable string representation.
42+
Every tuple is represented by brackets '()'. The individual elements of a tuple are
43+
separated by a semicolon ';'. The individual tuples are separated by a comma ','.
44+
An odml 3-tuple list of 2 tuples would be serialized to: "[(11;12;13),(21;22;23)]".
45+
46+
:param odml_tuples: List of odml style tuples.
47+
:return: string
48+
"""
49+
str_tuples = ""
50+
for val in odml_tuples:
51+
str_val = ";".join(val)
52+
if str_tuples:
53+
str_tuples = "%s,(%s)" % (str_tuples, str_val)
54+
else:
55+
str_tuples = "(%s)" % str_val
56+
57+
return "[%s]" % str_tuples

0 commit comments

Comments
 (0)