How can I strip first and last double quotes?

Walapa picture Walapa · Jun 21, 2010 · Viewed 212.8k times · Source

I want to strip double quotes from:

string = '"" " " ""\\1" " "" ""'

to obtain:

string = '" " " ""\\1" " "" "'

I tried to use rstrip, lstrip and strip('[^\"]|[\"$]') but it did not work.

How can I do this?

Answer

houbysoft picture houbysoft · Jun 21, 2010

If the quotes you want to strip are always going to be "first and last" as you said, then you could simply use:

string = string[1:-1]