예제 #1
0
def writefc (listoflists,colsize,file,writetype='w'):
    """
Writes a list of lists to a file in columns of fixed size.  File-overwrite
is the default.

Usage:   writefc (listoflists,colsize,file,writetype='w')
Returns: None
"""
    if type(listoflists) == N.ArrayType:
        listoflists = listoflists.tolist()
    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]
    n = [0]*len(list2print[0])
    for row in listoflists:
        if row == ['\n'] or row == '\n':
            outfile.write('\n')
        elif row == ['dashes'] or row == 'dashes':
            dashes = [0]*colsize
            for j in range(len(n)):
                dashes[j] = '-'*(colsize)
            outfile.write(pstat.lineincols(dashes,colsize))
        else:
            outfile.write(pstat.lineincols(row,colsize))
        outfile.write('\n')
    outfile.close()
    return None
예제 #2
0
파일: io.py 프로젝트: eddienko/SamPy
def writefc(listoflists, colsize, file, writetype="w"):
    """
Writes a list of lists to a file in columns of fixed size.  File-overwrite
is the default.

Usage:   writefc (listoflists,colsize,file,writetype='w')
Returns: None
"""
    if type(listoflists) == N.ndarray:
        listoflists = listoflists.tolist()
    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]
    n = [0] * len(list2print[0])
    for row in listoflists:
        if row == ["\n"] or row == "\n":
            outfile.write("\n")
        elif row == ["dashes"] or row == "dashes":
            dashes = [0] * colsize
            for j in range(len(n)):
                dashes[j] = "-" * (colsize)
            outfile.write(pstat.lineincols(dashes, colsize))
        else:
            outfile.write(pstat.lineincols(row, colsize))
        outfile.write("\n")
    outfile.close()
    return None