Ejemplo n.º 1
0
def DATA_Merger(infilename1, infilename2):
    filename_list1 = read_file_name(infilename1)
    infile1 = filename_list1[2]
    filename_list2 = read_file_name(infilename2)
    infile2 = filename_list2[2]
    DATE_ROW = MakeList_column(infile1)
    DATA_ROW = MakeList_column(infile2)
    for i in range(len(DATA_ROW)):
        DATE_ROW.append(DATA_ROW[i])
    NEWNAME = infile1.replace(".txt", "_MERGE_" + filename_list2[0])
    FN = NEWNAME + ".txt"
    Of = open(FN, "w+")
    for j in range(len(DATE_ROW[0])):
        for i in range(len(DATE_ROW)):
            Of.write("%s" % DATE_ROW[i][j])
            if (i != len(DATE_ROW) - 1):
                Of.write(" ")
            else:
                Of.write("\n")


#        Of.write("%s " %DATE_ROW[0][j])
#        Of.write("%s\n" %DATE_ROW[1][j])
    Of.close()
    return FN
Ejemplo n.º 2
0
def Merge(filename1, filename2):

    if(filename1[0]=="/"):
        filename1 = filename1
    elif((filename1[0]=="C")&(filename1[1]==":")):
        filename1 = filename1
    else:
        filename1 = os.getcwd() + "/" + filename1   # get the path included filename
    loca1=len(filename1)
    for i in range (1,len(filename1)+1):       # find the "/" location
        if(filename1[-i] == "/"):
            loca1 = i-1
            break
    FILENAME1 = filename1.replace(filename1[:-loca1],"")   # this is the shorten filename
    filename1_No_Txt = FILENAME1.replace(".txt","")
    infile1 = filename1

    if(filename2[0]=="/"):
        filename2 = filename2
    elif((filename2[0]=="C")&(filename2[1]==":")):
        filename2 = filename2
    else:
        filename2 = os.getcwd() + "/" + filename2   # get the path included filename
    loca2=len(filename2)
    for i in range (1,len(filename2)+1):       # find the "/" location
        if(filename2[-i] == "/"):
            loca2 = i-1
            break
    FILENAME2 = filename2.replace(filename2[:-loca2],"")   # this is the shorten filename
    filename2_No_Txt = FILENAME2.replace(".txt","")
    infile2 = filename2

    DATE_ROW = MakeList_column(infile1)
    DATA_ROW = MakeList_column(infile2)
#    DATE_ROW.append(DATA_ROW[0])
    for i in range(len(DATA_ROW)):
        DATE_ROW.append(DATA_ROW[i])
#    print(DATE_ROW)
#    print(len(DATE_ROW[0]))
#    print(len(DATE_ROW[1]))

    NEWNAME = infile1.replace(".txt","_MERGE_"+filename2_No_Txt)
    FN = NEWNAME+".txt"
    Of = open(FN,"w+")
    for j in range(len(DATE_ROW[0])):
        for i in range(len(DATE_ROW)):
            if DATE_ROW[i][j] is None:
                continue
            else:
                Of.write("%s" %DATE_ROW[i][j])
                if(i != len(DATE_ROW)-1):
                    Of.write(" ")
                else:
                    Of.write("\n")

#        Of.write("%s " %DATE_ROW[0][j])
#        Of.write("%s\n" %DATE_ROW[1][j])
    Of.close()
    return FN
Ejemplo n.º 3
0
def ROW_COL(filename1, filename2):

    if (filename1[0] == "/"):
        filename1 = filename1
    elif ((filename1[0] == "C") & (filename1[1] == ":")):
        filename1 = filename1
    else:
        filename1 = os.getcwd(
        ) + "/" + filename1  # get the path included filename
    loca1 = len(filename1)
    for i in range(1, len(filename1) + 1):  # find the "/" location
        if (filename1[-i] == "/"):
            loca1 = i - 1
            break
    FILENAME1 = filename1.replace(filename1[:-loca1],
                                  "")  # this is the shorten filename
    filename1_No_Txt = FILENAME1.replace(".txt", "")
    infile1 = filename1

    if (filename2[0] == "/"):
        filename2 = filename2
    elif ((filename2[0] == "C") & (filename2[1] == ":")):
        filename2 = filename2
    else:
        filename2 = os.getcwd(
        ) + "/" + filename2  # get the path included filename
    loca2 = len(filename2)
    for i in range(1, len(filename2) + 1):  # find the "/" location
        if (filename2[-i] == "/"):
            loca2 = i - 1
            break
    FILENAME2 = filename2.replace(filename2[:-loca2],
                                  "")  # this is the shorten filename
    filename2_No_Txt = FILENAME2.replace(".txt", "")
    infile2 = filename2

    COL_LIST1 = MakeList_column(infile1)
    COL_LIST2 = MakeList_column(infile2)
    COL_LIST1.append(COL_LIST2[1])
    COL_LIST3 = COL_LIST1

    #    print(COL_LIST3)

    ROW_LIST4 = []

    for k in range(len(COL_LIST3[0])):
        gg = []
        for m in range(len(COL_LIST3)):
            gg.append(COL_LIST3[m][k])

        ROW_LIST4.append(gg)


#    print(ROW_LIST4)

    NEWNAME = infile1.replace(".txt", "_" + filename2_No_Txt)
    FN = NEWNAME + ".txt"
    Of = open(FN, "w+")
    for i in range(len(ROW_LIST4)):
        for j in range(len(ROW_LIST4[i])):
            Of.write("%s" % ROW_LIST4[i][j])
            if (j != len(ROW_LIST4[i]) - 1):
                Of.write(" ")
            if (j == len(ROW_LIST4[i]) - 1):
                Of.write("\n")
    Of.close()

    return FN