[Tutor] Using subprocess on a series of files with spaces

C Smith illusiontechniques at gmail.com
Thu Jul 31 23:53:26 CEST 2014


>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