示例#1
0
def writecc(listoflists, file, writetype='w', extra=2):
    """
Writes a list of lists to a file in columns, customized by the max
size of items within the columns (max size of items in col, +2 characters)
to specified file.  File-overwrite is the default.

Usage:   writecc (listoflists,file,writetype='w',extra=2)
Returns: None
"""
    if type(listoflists[0]) not in [ListType, TupleType]:
        listoflists = [listoflists]
    outfile = open(file, writetype)
    rowstokill = []
    list2print = copy.deepcopy(listoflists)
    for i in range(len(listoflists)):
        if listoflists[i] == [
                '\n'
        ] or listoflists[i] == '\n' or listoflists[i] == 'dashes':
            rowstokill = rowstokill + [i]
    rowstokill.reverse()
    for row in rowstokill:
        del list2print[row]
    maxsize = [0] * len(list2print[0])
    for col in range(len(list2print[0])):
        items = pstat.colex(list2print, col)
        items = map(pstat.makestr, items)
        maxsize[col] = max(map(len, items)) + extra
    for row in listoflists:
        if row == ['\n'] or row == '\n':
            outfile.write('\n')
        elif row == ['dashes'] or row == 'dashes':
            dashes = [0] * len(maxsize)
            for j in range(len(maxsize)):
                dashes[j] = '-' * (maxsize[j] - 2)
            outfile.write(pstat.lineincustcols(dashes, maxsize))
        else:
            outfile.write(pstat.lineincustcols(row, maxsize))
        outfile.write('\n')
    outfile.close()
    return None
示例#2
0
文件: io.py 项目: eddienko/SamPy
def writecc(listoflists, file, writetype="w", extra=2):
    """
Writes a list of lists to a file in columns, customized by the max
size of items within the columns (max size of items in col, +2 characters)
to specified file.  File-overwrite is the default.

Usage:   writecc (listoflists,file,writetype='w',extra=2)
Returns: None
"""
    if type(listoflists[0]) not in [ListType, TupleType]:
        listoflists = [listoflists]
    outfile = open(file, writetype)
    rowstokill = []
    list2print = copy.deepcopy(listoflists)
    for i in range(len(listoflists)):
        if listoflists[i] == ["\n"] or listoflists[i] == "\n" or listoflists[i] == "dashes":
            rowstokill = rowstokill + [i]
    rowstokill.reverse()
    for row in rowstokill:
        del list2print[row]
    maxsize = [0] * len(list2print[0])
    for col in range(len(list2print[0])):
        items = pstat.colex(list2print, col)
        items = map(pstat.makestr, items)
        maxsize[col] = max(map(len, items)) + extra
    for row in listoflists:
        if row == ["\n"] or row == "\n":
            outfile.write("\n")
        elif row == ["dashes"] or row == "dashes":
            dashes = [0] * len(maxsize)
            for j in range(len(maxsize)):
                dashes[j] = "-" * (maxsize[j] - 2)
            outfile.write(pstat.lineincustcols(dashes, maxsize))
        else:
            outfile.write(pstat.lineincustcols(row, maxsize))
        outfile.write("\n")
    outfile.close()
    return None