471,325 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Fwd: Python-list Digest, Vol 52, Issue 128

Fredrik Lundh wrote:
Adrian Wood wrote:

I can call man.state() and then woman.state() or Person.state(man) and
Person.state(woman) to print the status of each. This takes time and
space however, and becomes unmanageable if we start talking about a
large number of objects, and unworkable if there is an unknown number.
What I'm after is a way to call the status of every instance of Man,
without knowing their exact names or number.

I've gone through the relevant parts of the online docs, tried to find
information elsewhere online, and looked for code samples, but the
ionformation either isn't there, or just isn't clicking with me. I've
tried tracking the names of each object in a list, and even creating
each object within a list, but don't seem to be able to find the right
syntax to make it all work.

For a start, how about:

class Person:
... your class ...

persons = []

man = Person()
persons.add(man)

woman = Person()
persons.add(woman)

for p in persons:
print p, p.state()
It didn't like using .add for some reason, but once I swapped out all
instances of that for .append that worked a treat! Thank you very
much, I'll check out your other suggestions later once I feel
comfortable with what I have so far.
Jan 10 '08 #1
0 725

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Ralph Freshour | last post: by
reply views Thread by johan | last post: by
5 posts views Thread by Roman Suzi | last post: by
9 posts views Thread by Mayer | last post: by
reply views Thread by Mark Nottingham | last post: by
1 post views Thread by jake77.lucas | last post: by
7 posts views Thread by Yansky | last post: by
reply views Thread by Fredrik Lundh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.