Avatar of Tbalz
Tbalz

asked on 

How to escpate double quotes inside of single quotes in Python

Hi guys,

I was a python script that finds certain text and replaces it, however I can't seem to figure out how to escape double quotes inside of single quotes. Any ideas?

python - <<END
import string
s = open("/etc/init/control-alt-delete.conf").read()
s = s.replace('exec /sbin/shutdown -r now "Control-Alt-Delete pressed"', 'exec /usr/bin/logger -p security.info "Ctrl-Alt-Delete pressed"')
f = open("/etc/init/control-alt-delete.conf", 'w')
f.write(s)
f.close()
END

Open in new window

PythonLinuxProgramming

Avatar of undefined
Last Comment
simon3270

8/22/2022 - Mon