mp3info dando un error con el nombre de archivo variable

I have been using mp3info to calculate my file length using the following syntax:

 mp3info -p "%S" /path/to/file

whenever I use the code with the filename I get the correct output:

 mp3info -p "%S" far_from_love.mp3

However, on storing the filename in a string variable and then using the variable I get an error:

 SyntaxError: invalid syntax

Could anyone tell me how to correctly use the command with a variable filename?

this is the python code which uses mp3info

for f in listing:
    if fnmatch.fnmatch(f,'*.mp3'):

         ext=f[:-4]                             #extract name of file without extension
         print WAVE_OUTPUT_FILENAME#save output filename as wav extension
         print f
         x=os.popen('mp3info -p "%S" f).read()
         print x

preguntado el 08 de noviembre de 11 a las 11:11

Please also include the relevant Python code. -

1 Respuestas

x=os.popen('mp3info -p "%S" f).read()

is missing a closing quote:

x=os.popen('mp3info -p "%S" ' + f).read()

You may also want to use the safer subprocess módulo:

import subprocess
x = subprocess.check_output(['mp3info', '-p', '%S', f])

respondido 08 nov., 11:16

thanks a lot! that solved my problem,i got the syntax of adding f wrong (didn't use +f) - user887112

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.