If you know what a CommaSeparatedValues file looks like, then reading ONE LINE gives you enough info to answer the question about how many columns of data it describes.
-----Original Message----- From: Tutor <tutor-bounces+avigross=verizon....@python.org> On Behalf Of Alan Gauld via Tutor Sent: Thursday, December 13, 2018 7:47 PM To: tutor@python.org Subject: Re: [Tutor] Python function On 13/12/2018 17:21, Sammy Lee wrote: > How do I create a python function that opens a CSV file and determines > how many columns of data are in the file? The CSV files have been > randomly generated from https://www.mockaroo.com/ > > def csv_column_count(openfile): You will find a bunch of stuff on creating functions in the Functions and Modules topic of my tutorial.(see below) You will find a bunch of stuff on handling files in the Handling Files topic of my tutorial.(see below) You will find a lot of help on using CSV files in the csv module documentation in the standard library. (Or you could buy my book "Python Projects" which has a section on the topic.) -- 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 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor