Lists of attributes

Bruce Eckel Bruce at EckelObjects.com
Thu Dec 6 14:56:34 EST 2001


If I have:

class Flower:  
  def accept(self, visitor):
    visitor.visit(self)
  def __repr__(self):
    return self.__class__.__name__

class Gladiolus(Flower): pass
Flower.gladiolus = Gladiolus()

class Runuculus(Flower): pass
Flower.runuculus = Runuculus()

class Chrysanthemum(Flower): pass 
Flower.chrysanthemum = Chrysanthemum()

Is there a clever way to get a list containing
[Flower.gladiolus, Flower.runuculus, Flower.chrysanthemum]

I've got:
[j for i,j in Flower.__dict__.items() if Flower in
j.__class__.__bases__]
But I was hoping for something less awkward...

Most current information can be found at:
http://www.mindview.net/Etc/notes.html
===================
Bruce Eckel    http://www.BruceEckel.com
Contains free electronic books: "Thinking in Java 2e" & "Thinking
in C++ 2e"
Please subscribe to my free newsletter -- just send any email to:
join-eckel-oo-programming at earth.lyris.net
My schedule can be found at:
http://www.mindview.net/Calendar
===================






More information about the Python-list mailing list