Aug-24-2018, 06:18 AM
I am reading a csv file whose data structures looks like this
i am trying to read it and convert it into comma separated list so that i can access every element separately
below is my code:
Like this i want to read it
i am trying to read it and convert it into comma separated list so that i can access every element separately
below is my code:
def Residential(): global url, parse_url filename = "Residential.csv" f = open(filename, "r") for line in f.readlines(): data = line.split(",") builderid = data[0] print(builderid) buildername = data[1] print(buildername) buildingname = data[2] print(buildername) address = data[3] city = data[4] locality = data[5] building_id = data[6] apartment = data[7].replace("\"","") print(type(apartment)) status = data[8].replace("\"","") print(status) cdate = data[9] bhk = data[10] rnumber = data[11] rurl = data[12] print(data) Residential()element 7 and 10 which are property type and bhk also got separated by "," how can i not to separate these by comma and read element 7 into list and element 10 as it is.
Like this i want to read it
['11916', 'testBuild', 'Test Building', 'Udaipur sector-5 Hiran Magri', '181', '753180', '794950', [1,2], 'UC', '2018-08-22', "2BHK, 3BHK", '', '\n']this is result i have received:
['11916', 'testBuild', 'Test Building', 'Udaipur sector-5 Hiran Magri', '181', '753180', '794950', '"1', '2"', 'UC', '2018-08-22', '"2BHK', ' 3BHK"', '', '\n']