Thread: Coding help

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Location
    Delhi
    Posts
    35
    Rep Power
    2

    Question Coding help


    Time.pdf is format of csv file. I wanna modify the csv file in format actual.pdf. how to make change in my code to get actual format


    strip.py
    <code>

    import csv




    def test_strip():
    # open input csv for reading
    inputCSV = open(r'time.csv', 'rb')
    outputCSV = open(r'time1.csv', 'wb')
    appendCSV = open(r'time1.csv', 'ab')
    cr = csv.reader(inputCSV, dialect = 'excel')
    cw = csv.writer(outputCSV, dialect = 'excel')
    ca = csv.writer(appendCSV, dialect = 'excel')
    for row in cr:
    if row or any(row) or any(field.strip() for field in row):
    ca.writerow(row)
    inputCSV.close()
    outputCSV.close()
    appendCSV.close()


    def fopen():
    f=open("test.csv","w+");
    #result = csv.writer(f,delimiter=',')
    result = csv.writer(f,delimiter=',', dialect='excel-tab')
    result_statement=("hour","min","sec")
    result.writerow(result_statement)
    f.close()


    def fh_open():
    f=open("trial.csv","w+");
    #result = csv.writer(f,delimiter=',')
    result = csv.writer(f,delimiter=',', dialect='excel-tab')
    result_statement=("hour","min","sec")
    result.writerow(result_statement)
    f.close()



    import csv
    import matplotlib.pyplot as plt


    def graph1():

    plt.figure()
    file =open("time1.csv","r+")
    reader = csv.reader(file)
    TS=[]
    TIME=[]
    ACT_ANGLE=[]
    DES_ANGLE=[]
    for line in reader:

    #TS.append(line[12])
    # TIME.append(line[5])
    ACT_ANGLE.append(line[7])
    DES_ANGLE.append(line[6])


    #del TS[0]
    #del TIME[0]
    del ACT_ANGLE[0]
    del DES_ANGLE[0]

    #print TS
    #x=TS
    #x=[]
    #print ("ts value is :\n"),TS
    z=ACT_ANGLE
    #print x
    y=DES_ANGLE


    plt.plot(y)
    plt.plot(z)
    plt.xlabel('Time in Sec')
    plt.ylabel('Actual angle in degree')
    plt.show()
    plt.savefig("example.png")
    </code>

    main.py

    <code>


    import csv
    from strip import test_strip
    from strip import fopen
    from strip import graph1
    from strip import fh_open
    import string

    def main():
    pass

    if __name__ == '__main__':
    main()
    fh_open()
    test_strip()
    count=0
    while(count<=2):
    TS=[]
    HOUR=[]
    TIME=[]
    TIME1=[]
    TIME2=[]

    file =open("time1.csv","r+")
    reader = csv.reader(file)
    for line in reader:
    TS.append(line[5])
    TIME=str(TS)
    # val.remove[0]
    #del val[0]

    TIME2=(TIME.split(","))
    f=open("trial.csv","w+");

    #result = csv.writer(f,delimiter=',')
    result = csv.writer(f,delimiter=',', dialect='excel-tab')
    result.writerow(TIME[1:])
    result.writerow(TIME2[1:])
    f.close()


    f=open("trial.csv","r+");
    TIME1=(TIME.split("."))
    #result = csv.writer(f,delimiter=',')
    result = csv.writer(f,delimiter=',', dialect='excel-tab')
    result.writerow(TIME[1:])
    f.close()

    count=count+1
    print count
    f.close()



    </code>
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo