-3

I have the following list

a = [ documents/17361862_1455215234500329_3000435910753279754_n.jpg,  documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg]

and I want to achieve the following

[ "documents/17361862_1455215234500329_3000435910753279754_n.jpg",  "documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg"] 

I tried this

x= ['{0}'.format(i) for i in a]

print x

but I get the following error

 File "list.py", line 3

    a = [ documents/17361862_1455215234500329_3000435910753279754_n.jpg,  documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg] 
                                                                  ^
SyntaxError: invalid syntax

how can I add quotes so as to get

[ "documents/17361862_1455215234500329_3000435910753279754_n.jpg",  "documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg"] 
Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
felix
  • 13
  • 2
  • 6
  • Have you tried add them directly in your script ? – Tbaki Jun 29 '17 at 13:32
  • I have tried but its not working , my question is same as this one https://stackoverflow.com/questions/16054870/how-to-convert-list-into-string-with-quotes-in-python but only the data is different, instead of mylist = [1,2,3] , mine would look something like mylist=[documents/17361862_1455215234500329_3000435910753279754_n.jpg, documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg] – felix Jun 29 '17 at 14:34
  • it is not, 1,2,3 are int, which is legal sytaxe in python. You should write `mylist=[ "documents/17361862_1455215234500329_3000435910753279754_n.jpg", "documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg"]` in your script, you can only pass those caracters as strings. – Tbaki Jun 29 '17 at 14:45
  • Thank you very much for reminding me that , I was treating strings like integers – felix Jun 29 '17 at 14:55
  • No problem, hope that solved your problem. : ) – Tbaki Jun 29 '17 at 15:05

2 Answers2

0

If you mean to print a string in quotation marks you can do one of the following:

"ASDFG 'those will show' Asdfg"
'ASDFG "Those will show" Asdfg'
"Asdfg \"Those will show\" Asdfg"

If you intend on converting the items to a string you do:

str(YOUR OBJECT)

Maybe your code has a problem with your dot placement. That usually indicates an attribute of a class.

IcyTv
  • 405
  • 4
  • 12
  • Thank you for your response , my question is similar to https://stackoverflow.com/questions/16054870/how-to-convert-list-into-string-with-quotes-in-python but instead of mylist=[1,2,3] ,mine would look like mylist=[documents/17361862_n.jpg, documents/1702gqbi7GG.jpg] , thank you icy TV – felix Jun 29 '17 at 14:44
  • But to add quotes you need the data to be a string right? You could do: for i in mydata: res += "'{}'".format(i) Or: res = [] for i in mydata: res.append("'{}'".format(i)) – IcyTv Jun 29 '17 at 14:50
0

If you want to add quotation mark at your list, you can do this :

a = [ "\"documents/17361862_1455215234500329_3000435910753279754_n.jpg\"", "\"documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg\""]

I am sorry if I am wrong.

Armand Dwi
  • 137
  • 5
  • Thank you my question is similar to this https://stackoverflow.com/questions/16054870/how-to-convert-list-into-string-with-quotes-in-python but my data is a little bit different instead of mylist=[1,2,3] the data looks like mylist= [documents/17361862_1455215234500329_3000435910753279754_n.jpg, documents/17022254_1431360773552442_8479986202582740765_n_gqbi7GG.jpg] , thanks in advance – felix Jun 29 '17 at 14:38