Example #1
0
def list_to_hf3(seq):
    """transfers a seq of values into a string for hiflow3.
    :param seq: a sequence (iterable) of value (int, float, ...)
    :rtype: str

    >>> points = map(float, [1,2,3]*3)
    >>> list_to_hf3(points)
    "1.0,2.0,3.0;1.0,2.0,3.0;1.0,2.0,3.0"
    """
    from cStringIO import StringIO

    s = StringIO()

    for i, p in enumerate(seq, 1):
        s.write("%0.15f" % float(p))

        if i % 3 == 0 and i != 1:
            s.write(";")
        else:
            s.write(",")

    s = s.getvalue()[:-1]
    assert s.count(';') + 1 == len(seq) / 3
    return s