Python/Bash - Get filenames with escaped characters Python/Bash - Get filenames with escaped characters shell shell

Python/Bash - Get filenames with escaped characters


The underlying problem sounds like passing file names that may contain characters that would need to be escaped as arguments to another program. I suggest looking at subprocess.

Specifically, see frequently used arguments:

args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

For example:

import subprocessfile_names = [r'AA - BB (CC) [DD]', r'EE - FF (GG) [HH]', r'II - JJ (KK) [LL]']for file_name in file_names:    subprocess.call([r'touch', file_name])


Your variable is ok. Try using print(escaped) not escaped alone.