I have a csv file with first 2 entries like this:
"objectId","url"
"1","someUrl1"
"2","[\"SomeUrl2\",\"SomeUrl3\"]"
I want to read the csv in python such that I can extract the id and the url as has to be a single variable irrespective of whether it is a string or an array of strings. Each row will have exactly one id. Urls can be one as shown above.
- For 1: Id I need: 1. url I need: "someUrl1"
- For 2: Id I need: 2. url I need: "["SomeUrl2","SomeUrl3"]"
I tried reading the csv as usual.
def loadList(fileName):
inpFile = open(fileName, "r")
li = list()
with inpFile:
csvreader = csv.reader(inpFile)
for row in csvreader:
print(row,"\n")
# line = row.strip()
li.append(row)
inpFile.close()
return li
But this delimits across all commas and thats not what I need