[Chicago] create all classes

Lukasz Szybalski szybalski at gmail.com
Fri Feb 1 19:35:48 CET 2008


On Feb 1, 2008 11:06 AM, Kumar McMillan <kumar.mcmillan at gmail.com> wrote:
> On Feb 1, 2008 10:32 AM, Kumar McMillan <kumar.mcmillan at gmail.com> wrote:
> > you want
> >
> > import blocks, types
> > for name in dir(blocks):
> >     TheClass = getattr(blocks, name)
> >     if not type(TheClass)==types.ClassType:
> >         continue
> >     c = TheClass()
>
> mm, coffee, much better.
>
> I meant:
>
> if not type(TheClass)==type:
>     continue
>
> (to detect new-style classes) but you're probably better off giving
> all your 30 classes a common base class, i.e. MessageControl, and
> checking like this:
>
> if not type(TheClass)==type:
>     continue
> if not issubclass(TheClass, MessageControl):
>     continue
> c = TheClass()
> # more stuff

thanks, this kind of worked...
modified to check the subclass
 if type(x)==type:
            if issubclass(x,object):
                d.append(x())


What is the difference between:

class A:
    def __init__(self):
....
type <type 'classobj'>

class B(object):
    def __init__(self):
....
type: <type 'type'>


Shouldn't both be classobj?
Since they are not how can I tell this is a class I am after? What
would happen if I had a mix of both class A, class B(object)......?


Lucas
-- 
Copy paste python code
http://lucasmanual.com/mywiki/PythonManual


More information about the Chicago mailing list