newb: object factory, and iteration

C

Chris

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
 
J

Jeremy Yallop

Chris said:
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.
 

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

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top