473,378 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2159
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
12
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in programming so you'll have to bear with me... My...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
3
by: koutoo | last post by:
I have a code that writes to 2 seperate files. I keep getting a "list index out of range" error. The strange part is that when checking the files that I'm writing too, the script has already...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
2
by: as001 | last post by:
Hi, I'm writing a windows application in C# using VS 2003. I got stuck where it has to write multiple output text files. Here's my piece of code: for loop { Random r = new Random();...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.