shlex.quote()
does what you want since python 3.
(Use pipes.quote
to support both python 2 and python 3)
More Related Contents:
- how to get the time after two minutes [closed]
- Why do backslashes appear twice?
- Saving utf-8 texts with json.dumps as UTF8, not as \u escape sequence
- Using sudo with Python script
- Is there a simple way to get rid of junk values that come when you SSH using Python’s Paramiko library and fetch output from CLI of a remote machine?
- Decode escaped characters in URL
- Run Python script without Windows console appearing
- Running windows shell commands with python
- Execute multiple commands in Paramiko so that commands are affected by their predecessors
- How to escape special characters of a string with single backslashes
- Escape string Python for MySQL
- Execute terminal command from python in new terminal window?
- File not found error when launching a subprocess containing piped commands
- Shell Script: Execute a python program from within a shell script
- How to encode UTF8 filename for HTTP headers? (Python, Django)
- python getoutput() equivalent in subprocess [duplicate]
- Clear screen in shell
- Conda command working in command prompt but not in bash script
- How to store the result of an executed shell command in a variable in python? [duplicate]
- Python raw strings and trailing backslash [duplicate]
- Calling a python script from command line without typing “python” first
- How to prevent automatic escaping of special characters in Python [duplicate]
- How to run a python script from IDLE interactive shell?
- Adding backslashes without escaping [duplicate]
- In Python, how do I have a single backslash element in a list?
- Can’t execute shell script from python subprocess: permission denied
- Hiding console output produced by os.system
- Cannot find the file specified when using subprocess.call(‘dir’, shell=True) in Python
- How to execute a script remotely in Python using SSH?
- Python | change text color in shell [duplicate]