Multi-arrays python

B

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
 
P

Piet van Oostrum

b> Hi again!
b> After testing the whole day, I have got my goals from the last email, but
b> as always, another issues came up! and now that Ive been able to save a
b> list of list (or multi-arrays) as below :
b> ['100.mp3\n' '10008.mp3\n' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n']
b> ['10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
b> ['10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
b> ['10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n']
b> ['10008.mp3\n' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n']
b> I am not able to manipulate it again! I read it with:
b> Myfile.read() and all what I get is a str type data, what make my aim very
b> difficult to reach! What I want, is just to read one line(one specific
b> line, so I wouldnt have to read the whole file) and to get the numbers of
b> the songs from that line. Maybe I should save the information in another
b> way... But I just get those lines as lists, and write them in a file. Is
b> there a better way? I am very receptive to suggestions! Thanks again for
b> your help!

You are unclear about the syntax of your file. What is a line? Is this a
line?
['100.mp3\n' '10008.mp3\n' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n']

If so what do the \n after the filenames mean? Is \n a newline, or is it
a backslash followed by 'n'? In the first case then every filename is on
a separate line. So then you are mixing two concepts of line.

Anyhow you would make your life easier by getting rid of the \n's.

If all your filenames are numeric with the extension mp3 then the
following gives you a list of the filenames from a line:

In [31]: re.findall('[0-9]+\.mp3', line)
Out[31]: ['100.mp3', '10008.mp3', '10005.mp3', '10001.mp3', '10006.mp3']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top