Task 3 - abha-m/IoT-SPIT GitHub Wiki
Task 3 : Write a function in python to take 10 digit numbers from a text file/csv/xlxs (line by line ) print them on screen.
- First start by making three separate code files one for extracting data from each of the given file types.
- Before handling csv file and excel file in python we have to import their respective packages respectively . To do so use
impot csv
andimport xlrd
The following links can be used to learn more about the various syntax used in python for file handling
http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python
http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python
https://docs.python.org/2/library/csv.html
- Now to read the names and numbers in the respective files we can use the following in-built functions
readCSV = csv.reader(csvfile, delimiter=',')
and for excel files we can directly access each column or row by just using a simple for loop likefor i in sheet.col_values(0):
the for loop will iterate through each cell in the column - Once the Name and Number are read from the file store each of its value into a dictionary in python where the name will be the key and the number will be the value (This stores the names and numbers into an ordered array which can latter be used for searching for particular names and numbers )
- All the separate three codes can now be combined together to form a single code which when given a file will identify the file type and extract the data from it using the appropriate code for extraction, this can be done by taking input from the GUI, like a check-box which will tell type of file has been uploaded.