sam_com sam_com - 6 months ago 75
Python Question

python write string to a file without quotes

i am trying to write some string to a file but without quotes.
i check other solutions online but none of them worked for me.
so i am reading from a list and trying to write item[0] to a output.
i tried to map and do item[1:-1] but none of them worked
this my code:

for item in sorted(wrong_blocks):

this keep writing to the file:


but i just want:


without quotes

i checked this
Python - how to write strings to file without quotes and spaces?


You can remove all instances of a given set of characters from either side of a string with str.strip:

>>> s = '''"hello!"'''.strip('!"')
>>> print(s)

Change your output.write call to output.write(str(item[0]).strip('"')) and it will remove any unwanted quotes.