Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #
  2. # for my son
  3. # write by kyoung chip , jang
  4. #
  5. def test_db() :
  6. yield "0x01" , 100 , 210
  7. yield "0x02" , 300 , 220
  8. yield "0x03" , 400 , 230
  9.  
  10. def write_csv( csvfile ) :
  11. print(" csvfile = %s " % csvfile )
  12. w = ['data1,data2,data3']
  13. with open(csvfile, 'w') as f:
  14. c = 0
  15. for data1, data2, data3 in test_db():
  16.  
  17. print("data1 = %s " % data1 )
  18. w.append(
  19. data1 + ',' + str(data2) + ',' + str(data3)
  20. )
  21. c += 1
  22. if c == 1000:
  23. f.write('\n'.join(w) + '\n')
  24. w = []
  25. c = 0
  26. if c > 0:
  27. f.write('\n'.join(w) + '\n')
  28. f.write('\n')
  29. print('writen to %s' % csvfile)
  30.  
  31.  
  32. if __name__ == '__main__':
  33. write_csv('./test.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement