By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

newb: object factory, and iteration

P: n/a
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 =)

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Chris wrote:
But is there a way for me to list all instances of a certain

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.

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.