Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Фиксим CSV-файл
  2.  
  3. broken_csv = open("broken.csv", "r")
  4. csv = broken_csv.read()
  5. broken_csv.close()
  6.  
  7. csv = csv.replace(",", ".")
  8. csv = csv.replace("|", ",")
  9. csv = csv.replace(";REF#", "")
  10. csv = csv.replace("</span", "")
  11. csv = csv.replace("&amp;", "")
  12. csv = csv.replace("id,name,a,b\n", "")
  13. csv = csv.replace("#", ".")
  14. csv = csv.replace(",", ".")
  15.  
  16. # убираем точки в начале строк
  17. csv_lines = csv.split("\n")
  18. for line in csv_lines:
  19.     line += "/n"
  20. for line in csv_lines:
  21.     if line[0] == ".":
  22.         line = line[1:]
  23.  
  24. correct_csv = open("correct.csv", "w")
  25. correct_csv.writelines(csv_lines)
  26. correct_csv.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement