How to Read Data from CSV File in Python

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

# how to read data from CSV File
import csv,os,sys
try:
    if(os.path.isfile("c://myfile/emp.csv")):
        f=open("c://myfile/emp.csv","r")
        obj=csv.reader(f)
        mylist=list(obj)
        for row in mylist:
            for col in row:
                print(col,end=" ")
            print()        
    else:
        print("File Not Found......")    
except Exception as obj:
     print(obj)        
 

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *