Multi-arrays python

Discussion in 'Python' started by bbarbero@inescporto.pt, Oct 7, 2009.

  1. Guest

    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.
     
    , Oct 7, 2009
    #1
    1. Advertising

  2. >>>>> (b) wrote:

    >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']

    --
    Piet van Oostrum <>
    WWW: http://pietvanoostrum.com/
    PGP key: [8DAE142BE17999C4]
     
    Piet van Oostrum, Oct 14, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Grandy
    Replies:
    0
    Views:
    621
    John Grandy
    Sep 13, 2005
  2. Philipp
    Replies:
    21
    Views:
    1,135
    Philipp
    Jan 20, 2009
  3. akineko
    Replies:
    3
    Views:
    2,636
    Jesse Noller
    Jan 29, 2009
  4. Javier Montoya

    numpy arrays to python compatible arrays

    Javier Montoya, Jun 10, 2010, in forum: Python
    Replies:
    3
    Views:
    450
    Javier Montoya
    Jun 12, 2010
  5. Wirianto Djunaidi
    Replies:
    2
    Views:
    203
    Wirianto Djunaidi
    Apr 29, 2008
Loading...

Share This Page