You could simplify the call if you change the current working directory for the subprocess:
from subprocess import check_call
check_call(['sox'] + self.fileselected, cwd=chosendirectory)
Note: you don't need shell=True
unless you want to run an internal (shell builtin) command such as start
.
Backslashes has special meaning inside Python string literals in the source code.
>>> len('\\') == 1 # a single backslash inside the string
True
Backslashes has no special meaning in a string object (in memory) i.e., you shouldn't care about backslashes unless you manually write the paths in your Python source code -- if you read the path from a file; you don't need to escape them. If you read the paths from a GUI; you don't need to escape them. If you read the paths from the output of a subprocess; you don't need to escape them, etc.
If you print repr(path)
; it shows you how Python string literal would look like i.e., the backslashes are doubled (escaped). If you print: [path]
then it is equivalent to '['+repr(path)+']'
. If you print the string along print(path)
then repr
is not called on the string object and the backslashes are not doubled.
For Windows paths and regex patterns, you could use raw-string literal where backslashes are not escaped e.g., r'C:\Path\n\f' == 'C:\\Path\\n\\f'
(notice: r
prefix).