newb: object factory, and iteration

Discussion in 'Python' started by Chris, May 12, 2004.

  1. Chris

    Chris Guest

    I'm developing a thing that gathers data as follows:
    1. For all files of a certain name:
    I. for all lines in each of those files:
    i. split the /-separated values in each of those lines,
    and stuff them into a list (or dict or whatever)

    .... and this is for a hundred or so such files of that name, with each
    file having a hundred or so of such lines, with each line having 10 or
    so of such /-sep'd values.

    I thought that an instructive way of doing this would be to have a
    class describing each of these files and their contents, and create a
    new instance of this class for each file. As I'm writing this, it
    occurs to me that I could stick to a numbered naming convention (e.g.,
    df1, df2, etc) for when I need to access this data later in the
    program. But is there a way for me to list all instances of a certain
    class? I.e., if the classname were FileInfo, and I had hundred
    objects of that class, could I somehow loop:

    for all objects created from FileInfo
    do some stuff

    TIA for any help. I'll get used to Python sooner or later =)

    -cjl
     
    Chris, May 12, 2004
    #1
    1. Advertising

  2. Chris wrote:
    > But is there a way for me to list all instances of a certain
    > class?


    I don't think there is, in general. If, as in your example, you can
    modify the __init__ method of the class, you could add weak references
    to created instances to a class member list. It would be even nicer,
    though, to make a metaclass, instances of which maintain (weak)
    references to instances of themselves.

    Jeremy.
     
    Jeremy Yallop, May 12, 2004
    #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. Medi Montaseri
    Replies:
    17
    Views:
    905
    Medi Montaseri
    Sep 3, 2003
  2. Ryan Mitchley

    Object factory and Intel compiler

    Ryan Mitchley, Aug 5, 2004, in forum: C++
    Replies:
    2
    Views:
    465
    Marco Manfredini
    Aug 5, 2004
  3. Donald Newcomb

    NEWB: General purpose list iteration?

    Donald Newcomb, Aug 12, 2005, in forum: Python
    Replies:
    4
    Views:
    325
    Donald Newcomb
    Aug 12, 2005
  4. C#
    Replies:
    4
    Views:
    427
  5. Rudi
    Replies:
    5
    Views:
    5,236
Loading...

Share This Page