Poll: CSV file write
You do not have permission to vote in this poll.
modification in code
0%
0 0%
why i cant split the list
0%
0 0%
writing into csv file
0%
0 0%
Total 0 vote(s) 0%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seprating coma and write in to CSV file
#1
Dear all,
I have code as below. Which read data from serial port . I am trying to write these data into CSV file. please help me complete this code. I tried on py scripter it worked but code not working


code syntax
Code:
import serial
import csv
import string
import os
import time
import sys

def main():
    pass

if __name__ == '__main__':
    main()
    count=0
    f=open("test.csv","w+");
    result = csv.writer(f,delimiter=',', dialect='excel-tab')

    result_statememt=("date","time","Zenith","Azimuth","Elevation","conv_elevation");
    result.writerow(result_statememt)
    f.close()
    while(count<5):
        #time.sleep(60)
        ser=serial.Serial()
        ser.port=2
        ser.baudrate=9600
        ser.open()
        str=ser.read(109)
        print str
        val=str.split(":")
        print val
        print "\n"
        lines=str.split("\r\n")
        print lines
        #k=lines.split('')
        #print k
        l#ine=lines.split
        wst=[]

        #print line
        wst=[]
      for line in lines[:]:
             line=lines.split(":") [b]/*getting error saying list object has no attribute called split*/[/b]
              print line

        f=open("test.csv","a+")
        result=csv.writer(f,delimiter=',')

        count=count+1



        #lines=str.split("\r\n")

        #print count
        #f=open("test.txt","a+")
        #result=csv.writer(f,delimiter=',')
        #result.writerow()
        f.close()

    f.close()
    ser.close()


output file:

Code:
date is:7/12/16
time is:24-0-0
Zenith:104.85
Azimuth:110.40
Elevation:-14.85
Converted Elevation:15.79

['date is', '7/12/16\r\ntime is', '24-0-0\r\nZenith', '104.85\r\nAzimuth', '110.40\r\nElevation', '-14.85\r\nConverted Elevation', '15.79\r\n']


['date is:7/12/16', 'time is:24-0-0', 'Zenith:104.85', 'Azimuth:110.40', 'Elevation:-14.85', 'Converted Elevation:15.79', '']
Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\My Documents\python code\code1\module1.py", line 40, in <module>
    line=lines.split
AttributeError: 'list' object has no attribute 'split'
Reply
#2
Can I suggest that you visit HackForums.net? People will have more chance helping you over there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)