469,332 Members | 6,987 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Writing files

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()
Mar 19 '07 #1
3 2023
On Mar 19, 2:20 pm, Adonis Vargas <ado...@REMOVETHISearthlink.net>
wrote:
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?

Mike

Mar 19 '07 #2
ky******@gmail.com wrote:
<snip>
>>
-- 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?

Mike

Actually, I re-ran this in a terminal and it worked perfectly. I was
using IDLE to write this code, kinda peculiar. Maybe something to do
with IDLE and CSV (or writing to files) with lines ~1000. A socket
timing out maybe?

Thanks anyways.

Adonis
Mar 19 '07 #3
On 3/19/07, Adonis Vargas <ad****@removethisearthlink.netwrote:
Actually, I re-ran this in a terminal and it worked perfectly. I was
using IDLE to write this code, kinda peculiar. Maybe something to do
with IDLE and CSV (or writing to files) with lines ~1000. A socket
timing out maybe?
It's because your file never got closed. When you ran the script from
the terminal, your file was automatically closed when outCSV was
garbage collected. When you ran your script in IDLE outCSV was still
a live variable, so it wasn't garbage collected automatically. Since
you never told it to close the file, there was still data sitting in
the buffer waiting to be written.

--
Jerry
Mar 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

48 posts views Thread by Joseph | last post: by
10 posts views Thread by Neil Trigger | last post: by
6 posts views Thread by Sebastian Kemi | last post: by
12 posts views Thread by Chris Springer | last post: by
6 posts views Thread by arne.muller | last post: by
3 posts views Thread by koutoo | last post: by
20 posts views Thread by Marin Brkic | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.