I am using python Django and I have a CSV file which contains 4 fields name, abbreviation, address and type of school. I have 3 database table named university, type of university and university-type mapping.I am having a csv list which has name of university I want to compare it with university table present in database and want to find out id corresponding to that name and same process with type of university and find out its id.And then i want to insert those values into university-type mapping. I am able to read data from CVS using this method but stuck on database search for match: here is what i am using to read the search:
import csv
path = '/home/abi/Downloads'
file=open( path +"university.CSV", "r")
reader = csv.reader(file)
for line in reader:
t=line[1],line[2]
print(t)
NAME
NIT
Pune University
New University
Gujarat Technical University
Kuwait University - College of Business Administration جامعة الكويت - كلية العلوم الادارية
testuniversity
testuniversity
testuniversity23
testuniversity
Mumbai university
Mumbai university
California University
California University
California University
California University
California University
this is the one field in csv
and i have university sql table with field 'name' and i want to compare it CSV name and get the corresponding id from it
>>> import csv
>>> import pymysql
>>> import pymysql.cursors
>>> connection = pymysql.connect(user='root',password='root')
>>> path = '/home/abi/Downloads/'
>>> t=[]
>>> p=[]
>>> file = open(path +"university_list.csv - university_list.csv.csv","r" )
>>> reader = csv.reader(file)
>>> for line in reader:
... t=line[0]
... p=line[3]
... print t