[Tutor] Using subprocess on a series of files with spaces
C Smith
illusiontechniques at gmail.com
Fri Aug 1 00:34:41 CEST 2014
Actually, I can get re.sub() to print the filenames where they look
like they would be in the correct format for the shell, like this:
10\ track \number \ten.flac
but the shell still says that no such file exists, and I am sure I am
operating on them in the right place because I can modify them. So, I
am still wondering about that too.
On Thu, Jul 31, 2014 at 6:20 PM, C Smith <illusiontechniques at gmail.com> wrote:
> Okay I messed up with slash instead of backslash, so the re.sub()
> works, but I am still curious about the previous question.
>
> On Thu, Jul 31, 2014 at 6:14 PM, C Smith <illusiontechniques at gmail.com> wrote:
>> Even when I am using:
>> re.sub('/s', '\\/s', filename)
>> I am still getting the same output, even trying to assign the above to
>> a new variable doesn't work (as I wasn't sure if re.sub returned a new
>> value or changed filename in place, I tried both with)
>> Does the Python interpreter strip off backslashes or something with strings?
>>
>> On Thu, Jul 31, 2014 at 5:53 PM, C Smith <illusiontechniques at gmail.com> wrote:
>>>>Change:
>>>
>>>
>>>>subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
>>>
>>>>to:
>>>
>>>>subprocess.call(['ffmpeg', '-i', '"%s"' % filename, str(track)+'.mp3'])
>>>
>>> I still get the same errors, the filenames are passed to the shell
>>> without escaping the spaces.
>>>
>>>>Why not using ffmpeg without jumping into Python. It's well documented, check Google.
>>>
>>> I guess you mean that the ability to change multiple files with ffmpeg
>>> is possible. I hadn't considered that but I would rather do it with
>>> Python, just for the practice.
>>>
>>> On Thu, Jul 31, 2014 at 4:36 PM, Emile <emile at salesinq.com> wrote:
>>>> On 7/31/2014 1:19 PM, C Smith wrote:
>>>>>
>>>>> I get
>>>>> TypeError: unsupported operand type(s) for %: 'int' and 'str
>>>>> I am not understanding the use of the list inside the subprocess.call().
>>>>> I tried all of the following
>>>>> subprocess.call(['ffmpeg', '-i', '%s', str(track)+'.mp3']) % filename
>>>>> --gives type error stated above
>>>>> subprocess.call(['ffmpeg', '-i', '%s', str(track)+'.mp3'] % filename)
>>>>> --same
>>>>> subprocess.call(['ffmpeg', '-i', '%s', str(track)+'.mp3' % filename])
>>>>> -- TypeError: not all arguments converted during string formatting
>>>>> and tried all three with the triple quotes, just to be sure.
>>>>>
>>>>> On Thu, Jul 31, 2014 at 4:04 PM, Emile van Sebille <emile at fenx.com> wrote:
>>>>>>
>>>>>> You might try using '"%s"' % filename so that the name is within quotes
>>>>>> for the shell environment.
>>>>
>>>>
>>>> Change:
>>>>
>>>>
>>>> subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
>>>>
>>>> to:
>>>>
>>>> subprocess.call(['ffmpeg', '-i', '"%s"' % filename, str(track)+'.mp3'])
>>>>
>>>> Emile
>>>>
>>>>
>>>>
More information about the Tutor
mailing list