Я хочу импортировать два типа CSV файлов, некоторые используют ";" для разделителя и других используйте ",". До сих пор я переключался между следующими двумя строками:
reader=csv.reader(f,delimiter=';')
или
reader=csv.reader(f,delimiter=',')
Можно ли не указывать разделитель и позволить программе проверять правильный разделитель?
Решения ниже (Blender и sharth), похоже, хорошо работают для разделенных запятыми файлов (сгенерированных с помощью Libroffice), но не для разделенных точкой с запятой файлов (сгенерированных с помощью MS Office). Вот первые строки одного файла с разделителями с запятой:
ReleveAnnee;ReleveMois;NoOrdre;TitreRMC;AdopCSRegleVote;AdopCSAbs;AdoptCSContre;NoCELEX;ProposAnnee;ProposChrono;ProposOrigine;NoUniqueAnnee;NoUniqueType;NoUniqueChrono;PropoSplittee;Suite2LecturePE;Council PATH;Notes
1999;1;1;1999/83/EC: Council Decision of 18 January 1999 authorising the Kingdom of Denmark to apply or to continue to apply reductions in, or exemptions from, excise duties on certain mineral oils used for specific purposes, in accordance with the procedure provided for in Article 8(4) of Directive 92/81/EEC;U;;;31999D0083;1998;577;COM;NULL;CS;NULL;;;;Propos* are missing on Celex document
1999;1;2;1999/81/EC: Council Decision of 18 January 1999 authorising the Kingdom of Spain to apply a measure derogating from Articles 2 and 28a(1) of the Sixth Directive (77/388/EEC) on the harmonisation of the laws of the Member States relating to turnover taxes;U;;;31999D0081;1998;184;COM;NULL;CS;NULL;;;;Propos* are missing on Celex document