def build_string_from_array(arr, indent=12): result = "" if len(arr) == 1: """ arrays with one item contained on one line """ if len(arr[0]) > 0: if is_notstr_iterable(arr[0]): result += "[" + build_string_from_array(arr[0], indent + 4) + "]" else: result += "['%s']" % arr[0] else: result = '[[]]' elif len(arr) > 1: result = "[\n" for item in arr: if is_notstr_iterable(item): result += (" " * indent) + build_string_from_array(item, indent + 4) + ",\n" else: result += (" " * indent) + "'" + item + "',\n" result = result[:-2] + "\n" result += " " * (indent - 4) result += "]" else: result = '[]' return result
def build_string_from_array(arr, indent=12): result = "" if len(arr) == 1: """ arrays with one item contained on one line """ if len(arr[0]) > 0: if is_notstr_iterable(arr[0]): result += "[" + build_string_from_array(arr[0], indent + 4) + "]" else: result += "['{0!s}']".format(arr[0]) else: result = '[[]]' elif len(arr) > 1: result = "[\n" for item in arr: if is_notstr_iterable(item): result += (" " * indent) + build_string_from_array(item, indent + 4) + ",\n" else: result += (" " * indent) + "'" + item + "',\n" result = result[:-2] + "\n" result += " " * (indent - 4) result += "]" else: result = '[]' return result