python写mp3文件的一个程序

"""
   写mp3文件的一个程序,本程序于2015年5月编写,现在发到博客以肆读者。
   
"""

__author__ = '李兴球'
__date__ = '2015年5月'

import os
def setMp3Header(mp3file):
     mp3Id3V1 = {        
         "SongName":125,
         "SongPeople":95,
         "ZhuanJi":65,
         "Year":35,
         "Bak":31
         }
     tags = ['SongName','SongPeople','ZhuanJi','Bak']
     f = open(mp3file,'r+')
     filesize=os.path.getsize(mp3file)
     try:
         f.seek(filesize-128)
         try:
             tempstr = f.read(3)
             print(tempstr)
             if tempstr == 'TAG':  #在MP3文件的倒数每128个字节是TAG标签,否则认为不是MP3
                 for tag,startPos in mp3Id3V1.items():
                     print("writeMp3Header['%s']=%s" % (tag,writeMp3Header[tag]))
                     if writeMp3Header[tag] != '':
                         f.seek(filesize-startPos)
                         if tag in tags:
                             if len(writeMp3Header[tag]) > 30: 
                                 f.write(writeMp3Header[tag][:30])
                             else:
                                 f.write(writeMp3Header[tag])
                         print(startPos,tag,writeMp3Header[tag])
             else:
                 print('is not a mp3file')
         except IOError:
             print('read error')
     finally:
         f.close()


#定义字典
writeMp3Header = {
     "SongName":"",
     "SongPeople":"",
     "ZhuanJi":"",
     "Year":"",
     "Bak":""
     }

writeMp3Header['SongName'] = 'testsongname'
writeMp3Header['SongPeople'] = 'lixingqiu'
writeMp3Header['ZhuanJi'] = 'zhuangji'
writeMp3Header['Year'] = '2015'
writeMp3Header['Bak'] = 'www.scratch8.net'
setMp3Header(r'D:\CrazyFrogPlayTheGame.mp3')