On 25/06/18 20:35, Giulia Marcoux wrote: > Hello, > > I am a student learning python, and i am running into some difficulties. I > am tryign to read a csv file that has different delimiters for different > rows: Example: > > Format:V1.1 > Model: R > Step Size: 10mm > Distance: 10cm > Gain: 1000
Can you split your file here? That is could you just read the data from the first 5 lines (assuming its always in that kind of format) then spit the rest into a separate file (or stringbuffer?) and use CSV to analyze that? > X,Y > 1,3 > 2,5 > 6,5 > 5,7 > > For the X,Y data, I have no problem getting it into the right cells, > however I cannot separate the values after the colon for the first few > rows. Its either one or the other. A lot depends on the exact details of your file format. If the sample you've given is consistent with exactly the same header info in each (or at least some clear separating indicator - like X,Y in this case) Then its easy to split the data into two streams and process them separately. If the different formats are interlaced throughout the files things get more tricky. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor