Skip to main content

Posts

Showing posts with the label csv file

Reading of CSV File in Python Programming

How to read CSV file into Python Programming?  So, Here I have given Python Code and CSV file which I was used in Tutorial. Python Code: import csv with open("data.txt", "r") as dataFile: dataFileReader = csv.reader(dataFile) dataList = [] for row in dataFileReader: if len (row) != 0: dataList = dataList + [row] dataFile.close() print(dataList) CSV File : ABC, XYZ, 1, 2, 3 PQR, WXY, 4, 5, 6 DEF, JKL, 7, 8, 9 This Python code is made for a view and imports the comma separated files in python app. Also with this code user can only read this code in the app but They can't write in the file. import csv Now, Let's start with the first line of the program. So, in this line, i had imported the CSV library. and because of that, we can use functions like CSV file open, close, edit, read, write and etc. with open("data.txt", "r") as dataFile: This line has the function called 'open' which will be written ...

How to Writing into CSV File with Python Programming

how to write into a CSV file with a Python Programming? So, Here I have given Python Code and CSV file which I was used in Tutorial. Python Code: import csv with open("data.txt", "r") as dataFile: dataFileReader = csv.reader(dataFile) dataList = [] for row in dataFileReader: if len (row) != 0: dataList = dataList + [row] dataFile.close() print(dataList) name = input("Enter name: ") secondName = input("Enter secondName: ") value1 = input("value1: ") value2 = input("value2: ") value3 = input("value3: ") with open("data.txt", "a") as dataFile: dataFileWriter = csv.writer(dataFile) dataFileWriter.writerow([name, secondName, value1, value2, value3]) dataFile.close() CSV File : ABC, XYZ, 1, 2, 3 PQR, WXY, 4, 5, 6 DEF, JKL, 7, 8, 9 This Python code is made for a view, imports, and write the comma separated files in python app. Also with this code user can r...