I'm new to python and my in my first program I'm trying to extract metadata from FLAC files to rename them.
This particular part of my code is causing me some trouble:
import subprocess
filename = raw_input("Path?")
title = subprocess.call(
["metaflac", "--show-tag=title", filename])
new_title = title.replace("TITLE=", "")
print new_title
'metaflac --show-tag=title file.flac' sends back "TITLE=foo" and I'm trying to get rid of "TITLE=".
The problem is, when I run this, I get this back:
TITLE=foo
Traceback (most recent call last):
File "test.py", line 16, in <module>
title = title.replace("TITLE=", "")
AttributeError: 'int' object has no attribute 'replace'
I just don't understand how can the string "TITLE=Début d'la Fin" can be an integer...
subprocess.call
returns an integer (the exit code), not the output.
Use the stdout
argument, and call Popen.communicate()
:
pipe = subprocess.Popen(
["metaflac", "--show-tag=title", filename], stdout=subprocess.PIPE)
title, error = pipe.communicate()