hey every1, im a noob pythoneer.. i wanted to change the names of all music files using their metadata obtained from mminfo utility. I came up with the following hideous looking code..

import os

os.chdir(raw_input('plz enter directory name: '))
class process():
	def getmetadata(self,filename):
		command='mminfo %s|grep artist>temp.txt'%filename;#print command
		command='mminfo %s|grep title>temp.txt'%filename

	def __init__(self,filename):

	def get(self,s):#this returns the string after ':' in s
		return s[num+1:]
#print lst
for i in lst:
	#print i

yea.. u guessed right.. it doesn't work.. i checked the temp.txt.. it's not retrieving the proper data using the 'command'.. its always a blank file..

i think there has to be a better way to code the getmetadata() func. The reason im using the intermeditate temp.txt file is because i cant just write

t=os.system('mminfo file.mp3')

this just assigns either 0 or 1 to t and not the actual output from the command.
Plz tell me what is rong with this code.. also if you can tell me an alternate way to code getmetadata() plz do.. it seems ive probably coded the least efficient func of all time.. it takes a good 6 seconds to work on a dir with just 10 files!!:(

9 Years
Discussion Span
Last Post by zachabesh

Try to isolate the issue: Whenever I mesh python and the command line I usually try to test out the command first just using a command window. Then you can be sure that mminfo is working correctly. If so, maybe it's os.system call. Could be an enviroment issue, try putting the entire path to the mminfo executable, instead of just mminfo.

Additionally, you may want to make your temp.txt file part of the class. self.metadata_file or something similar. Also, when you are writing classes, capitals are nice and you don' t need the (). Ex:

class Process:
  def __init__(self):

Agreed on the hideous part. Split those lines up instead of the semicolons. I had to test that, I've never seen that before. :)


hmm ok.. sry im not well versed with the normal way of writing python progs yet.. gud news is.. this prog does what its sups o but only if there is one file in the directory.. hav luk guys.. plz tel me y its not working for more than one.. i hav a feeling it mayb because of the scope of objects..


You gonna have to give a little more info. You have a print statement commented out, does it at least try and process all the files? Is there an error?

And yes, you can't reference temp.txt in a class FIRST, and then try to reference it in the body of your script. Try passing it to the class.

Help me help you. ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.