Assuming that ["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"] is one long string as the original post seems to imply, ie:
"""["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"]"""
then the following code should work:
# ORIGINAL STRING
s = """["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"]"""
# GET RID OF UNNECESSARY CHARACTERS FOR OUR CSV
s = s.replace("][", "--") # temporary chars to help split into lines later on
s = s.replace("[", "")
s = s.replace("]", "")
s = s.replace("\'", "")
s = s.replace("\"", "")
# SPLIT UP INTO A LIST OF LINES OF TEXT
lines = s.split("--")
# WRITE EACH LINE IN TURN TO A CSV FILE
with open("myFile.csv", mode = "w") as textFile:
# mode = w to override any other contents of an existing file, or
# create a new one.
# mode = a To append to an exising file
for line in lines:
textFile.write(line + str("\n"))
["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"]do you mean-->['A','B','C']['a1,a2','b1','c1']['a2,a4','b3','ct']?"["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"]"? Because you cannot set a variable to that i.ea = ["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"]["'A','B','C'"]["'a1,a2','b1','c1'"]["'a2,a4','b3','ct'"]I have no idea what it could be. I didmydata = [mydata.replace("|", "")[1:-1]]because I had to replace the "|"'s I had in my data. The entire thing is definitely a string.