speed up linecache.getline()

2009-10-13 Thread bbarbero

Hi Everyone!!


I am using linecache.getline, to access to a line in a long file. It s  
really fast, appx 4seconds, but I was just wandering if any of you,  
know either another way, or there is something that I can do to speed  
it up...  thank you very much for your help!!


Regards,
Bea











Quoting Chris Rebert c...@rebertia.com:


On Wed, Oct 7, 2009 at 10:21 AM,  bbarb...@inescporto.pt wrote:

Hi again!

After testing the whole day, I have got my goals from the last email, but as
always, another issues came up! and now that Ive been able to save a list of
list (or multi-arrays) as below :

['100.mp3\n' '10008.mp3\n' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n']
['10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
['10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
['10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n']
['10008.mp3\n' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n']

I am not able to manipulate it again! I read it with:
Myfile.read() and all what I get is a str type data, what make my aim very
difficult to reach!  What I want, is just to read one line(one specific
line, so  I wouldnt have to read the whole file) and to get the numbers of
the songs from that line. Maybe I should save the information in another
way... But I just get those lines as lists, and write them in a file. Is
there a better way? I am very receptive to suggestions! Thanks again for
your help!


Have you considered using the `json` module
(http://docs.python.org/library/json.html) to serialize and
deserialize the lists to/from a file in JSON format?
The `pickle` module is another option:
http://docs.python.org/library/pickle.html

Cheers,
Chris
--
http://blog.rebertia.com






This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


Multi-arrays python

2009-10-08 Thread bbarbero

Hi again!

After testing the whole day, I have got my goals from the last email,  
but as always, another issues came up! and now that Ive been able to  
save a list of list (or multi-arrays) as below :


['100.mp3\n' '10008.mp3\n' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n']
['10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
['10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
['10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n']
['10008.mp3\n' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n']

I am not able to manipulate it again! I read it with:
Myfile.read() and all what I get is a str type data, what make my aim  
very difficult to reach!  What I want, is just to read one line(one  
specific line, so  I wouldnt have to read the whole file) and to get  
the numbers of the songs from that line. Maybe I should save the  
information in another way... But I just get those lines as lists, and  
write them in a file. Is there a better way? I am very receptive to  
suggestions! Thanks again for your help!


Best regards,
Bea Mora


This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


data matrix python

2009-10-07 Thread bbarbero

Good morning all!

I am trying to build a data matrix, but I am not able either to write  
to file with a proper structure nor to get the data from the matrix.


I want to sort some music by similarity content, and I just have the  
indexes of the playlist like this:


dm = numpy.array(songs)

[0 4 2 1 3]
[1 2 0 4 3]
[2 1 0 4 3]
[3 2 1 0 4]
[4 0 1 2 3]

Now, I want to keep the same format but with the names of the songs,  
something like this:


Sort_dm.append(songlist(dm))

['100.mp3\n' '10008.mp3' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n'
 '10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n'
 '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n'
 '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3'
 '10008.mp3' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n']

But there is no way either I can access to the data... because there  
are strings, or save them in matrix format! I could not find anything  
in the documentation about this! any hint would be very welcome! thank  
you for your time!


Best regards,
Bea Mora



This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


unexpected token `;'

2009-08-25 Thread bbarbero

Hello to all!

I am struggling with a script in python for a while now, and decided  
to look for some help. I am running a code that takes commands from  
Marsyas(open source for Music analysis).


#!/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
#!/bin/bashimport math
import re
import numpy
import string
import os.path
import sys
import commands



l =  
/Users/bmorab/Audio_Projecto/Data/Palco/PP3_44_distance_matrix/PP3_44_5.mf


Col = open(l, 'r')
colist= []
songlist = []
for line in Col:
#print line
song = os.path.split(line)[1]
#print song
songlist.append(song)
colist.append(line)



cmd = sfplay  + colist[2]
print cmd
fileout = commands.getoutput(cmd)
print fileout



It basically reads song files from the .mf file, stores them in a list  
and play  one of the songs from the list. It does work with some music  
but mostly it gives an error like this:


sfplay  
/Volumes/HAL/Datasets/Audio/PalcoPrincipal/mp3_resampled_44100/10005.mp3


sh: -c: line 1: syntax error near unexpected token `;'
sh: -c: line 1: `; } 21'


Ive been searching for the meaning of the error, and It really depends  
on the script, but I would conclude that I am missing a punctuation  
mark??


Thank you very much for taking your time reading my request.

Looking forward to hearing from you.

Regards,
Bea



This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


Extracting matrix from a text file

2009-08-07 Thread bbarbero

Hello to all!!

I am new in python, and I am running it on Mac with Smultron editor. I  
need to read a textfile that includes numbers (in a matrix form),  
indexes, and strings, like this:


Marsyas-kea distance matrix for MIREX 2007 Audio Similarity Exchange
Q/R 1   2   3   4   5
1   0   4.54592 4.36685 5.29463 3.85728
2   4.54592 0   3.97667 5.02151 4.64284
3   4.36685 3.97667 0   4.98743 4.83683
4   5.29463 5.02151 4.98743 0   6.04393
5   3.85728 4.64284 4.83683 6.04393 0



So I just want to keep the matrix in the middle for math computations.

0   4.54592 4.36685 5.29463 3.85728
4.54592 0   3.97667 5.02151 4.64284
4.36685 3.97667 0   4.98743 4.83683
5.29463 5.02151 4.98743 0   6.04393
3.85728 4.64284 4.83683 6.04393 0

I've seen and tried a lot of ways, like split or isinstance.. but  
never get the wanted result does anyone have an idea, or hint?  
Thank you once more for your help!


Best Regards,
Bea


This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


Problems in commands.getoutput(cmd) with sox

2009-07-23 Thread bbarbero

Hello to all!

I am a new researcher, new to Python as well, and I have a problem,  
when I try to get commands from sox in a python script. I am going  
crazy, because this code has been working before.. so I dont really  
know whats going on..


Ive already seen some solutions that match with what I have. I am  
running this:




if os.path.splitext(file_au)[1] == .au:
resampled_file_path = os.path.join(resampled_path, file_au)
cmd = sox  + dir_file +  -r 44100  + resampled_file_path
print cmd
output = commands.getoutput(cmd)
print output

What i do, is just to resample a song from dir_file to  
resampled_file_path. As a result of cmd I get:



sox /Volumes/HAL/Datasets/Audio/gtzan_genres/rock/rock.00097.au -r  
44100  
/Volumes/bmorab/Audio_Projecto/Data/gtzan_genres/resampled/rock/rock.00097.au

.

If I run this on the command line, it will work perfectly!

But The program stops at

 File  
/Volumes/bmorab/Audio_Projecto/Data/gtzan_genres/resamplingto44.py,  
line 35

output = commands.getoutput(cmd)
^
IndentationError: unexpected indent

I dont have any idea, whats going on, I am trying lot of things, but I  
can understand where is the error as it has been running perfectly  
before.


Any suggestions will be more than welcome! Thanks in advance for your help!

Best regards,
Beatriz Mora.




This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list