0

I have a Django query that returns me an array of strings. I am trying to convert them into a comma separated string.

array_string = "['xyz2005.test.com', 'xyz2006.test.com']"


(Pdb) joined_string = ",".join(array_string)
(Pdb) joined_string
"[,',x,y,z,2,0,0,5,.,t,e,s,t,.,c,o,m,',,, ,',x,y,z,2,0,0,6,.,t,e,s,t,.,c,o,m,',]"

I was expecting:

xyz2005.test.com, xyz2006.test.com

What am I doing wrong?

newbie
  • 873
  • 17
  • 41
  • 2
    I don't think this should have been closed. Decode the array using array_string = json.loads(array_string) first. Then use join. – OneLiner Nov 04 '20 at 14:47
  • @OneLiner: I am getting this error on array_string = json.loads(array_string): *** simplejson.errors.JSONDecodeError: Expecting value: line 1 column 2 (char 1) – newbie Nov 07 '20 at 00:31
  • Would need to see your exact code, including the import. Are you importing loads from json? – OneLiner Nov 08 '20 at 01:03

0 Answers0