In message
<[email protected]>, [email protected] wrote:
> The shell don't understand the special chars so i have to escape them with
> "\" .
> Is there a function that does this ?
You could get the shell (at least if it’s Bash) itself to do this. Try the
following script:
import sys
import os
import subprocess
os.environ["ARG1"] = sys.argv[1]
sys.stdout.write \
(
subprocess.Popen
(
args = "printf $'%q\\n' \"$ARG1\"",
stdout = subprocess.PIPE,
shell = True
).communicate()[0]
)
Sample output:
l...@theon:hack> ./escape_try '<gt>\ & # *'
\<gt\>\\\ \&\ #\ \*
--
http://mail.python.org/mailman/listinfo/python-list