read_text_lines.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import csv
  2. import math
  3. def printsection(b):
  4. #print(b)
  5. obj = dict(zip(b[::2], b[1::2]))
  6. for keys, values in obj.items():
  7. if keys == '1':
  8. try:
  9. #print(values)
  10. #print('{},{}'.format(obj['10'], obj['20']))
  11. #print("\n")
  12. row = [values,math.floor(float(obj['10'])),math.floor(float(obj['20']))]
  13. with open('text.csv', 'a') as csvFile:
  14. writer = csv.writer(csvFile, delimiter =';')
  15. if row[0] != '':
  16. writer.writerow(row)
  17. csvFile.close()
  18. except:
  19. print("ERROR")
  20. #print(b)
  21. #if obj.get('1'):
  22. # print('{}'.format(obj['1']))
  23. buffer = []
  24. file = open("Stahl_Adapterplatte.DXF", "r")
  25. for line in file:
  26. line = line.strip()
  27. #print(line)
  28. if line == '100': # we've started a new section, so
  29. printsection(buffer) # handle the captured section
  30. buffer = [] # and start a new one
  31. buffer.append(line)
  32. printsection(buffer)