I'm sending a file to a function in python, and trying to save the results to a variable, but I keep getting that error.
I've looked over the other answers but nothing seems to fit. Any help is appreciated:
def ffmpegLUFS(fileName):
subprocess.Popen("ffmpeg -i %s -filter_complex ebur128 -f null - 2>&1 | grep -n '.*' | grep -A 5 'size' | grep 'I:' | cut -d ':' -f3-" % tuple(map(pipes.quote, sys.argv[1])),stdout=subprocess.PIPE,shell=True).communicate()[0]
return
Traceback (most recent call last):
File "/Volumes/videos/videos/DROP_BIN/CHRIS/POD_Workflow_Files/WebContent_Audio.py", line 30, in <module>
sourceLUFS = ffmpegLUFS(sys.argv[1])
File "/Volumes/videos/videos/DROP_BIN/CHRIS/POD_Workflow_Files/WebContent_Audio.py", line 18, in ffmpegLUFS
subprocess.Popen("ffmpeg -i %s -filter_complex ebur128 -f null - 2>&1 | grep -n '.*' | grep -A 5 'size' | grep 'I:' | cut -d ':' -f3-" % tuple(map(pipes.quote, fileName)),stdout=subprocess.PIPE,shell=True).communicate()[0]
TypeError: not all arguments converted during string formatting
I'm not sure what you're trying to achieve with this part of your code:
tuple(map(pipes.quote, sys.argv[1]))
The Python map
function takes a function and an iterable and returns a list obtained by applying the function to each element of the iterable [1] . In your case, the iterable is a string, and the elements of the string are its characters, so the result of map(pipes.quote, sys.argv[1])
will be a list of characters from your string, quoted as necessary. For example, if sys.argv[1]
is 10 characters long, map(pipes.quote, sys.argv[1])
will be a list of length 10.
I could only see one %s
placeholder in your command-line string, so unless sys.argv[1]
happens to contain only one character, you will encounter the 'not all arguments converted...' exception, because the number of %s
placeholders in your string differs from the number of values you are attempting to put into the string.
As I see it, the simplest fix is to remove the calls to tuple
and map
and just use pipes.quote(sys.argv[1])
instead.
[1] map()
can actually take more than one iterable, but for simplicity I'm ignoring this. When given two arguments it behaves as I have described.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.