Writing files

kyosohma at gmail.com kyosohma at gmail.com
Mon Mar 19 20:35:21 CET 2007

On Mar 19, 2:20 pm, Adonis Vargas <ado... at REMOVETHISearthlink.net>
> I am writing a program that walks a directory full of mp3s reads their
> ID3 data (using Mutagen), this part works perfectly. The problem is I
> write these tags to a CSV file through the CSV module. But when I read
> the file the file seems to be incomplete. Further inspecting it has
> seemed to have stopped writing to the file at a certain point. Something
> in my code? a bug?
> System: Linux 2.4.31 (Slackware), Python 2.5c1
> Any help is greatly appreciated.
> Adonis
> -- code --
>      def _scan(self):
>          outFile = file("mp3.dat", "wb")
>          outCSV = csv.writer(outFile)
>          output = list()
>          for root, dirs, files in os.walk(self.directory):
>              files = [x for x in files if x.endswith(".mp3")]
>              for aFile in sorted(files):
>                  mp3Data = MP3(os.path.join(root, aFile))
>                  title = mp3Data.get("TIT2")
>                  output.append([root, aFile, title])
>              outCSV.writerows(output)
>              output = list()

Are you closing the file before you try to read it? Other than that,
I'm drawing a blank with just this sample to work with. Maybe someone
else will know...or you could post more code?


More information about the Python-list mailing list