escape a string for shell commands in Python -


this question has answer here:

i'm interested escape string in python3.x, such as:

some_macro(a, b) 

into...

some_macro\(a,\ b\) 

... can passed program (not gcc in case) define,

eg,

some_program -dsome_macro\(a,\ b\)="some expression" 

i expect shlex have functionality didn't find how , checked many similar questions already.

i don't mind write simple function this, seems kind of thing python include.

note: the program i'm passing argument wont accept:

-d"some_macro(a, b)"="some expression" 

... expects first character identifier.

doing correctly means not having worry this. shell has worry spaces , quotes , parens; python not.

proc = subprocess.popen([..., "-dsome_macro(a, b)=some expression", ...], ...) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -