mark sparshatt
2/7/2005 10:06:00 AM
Lethalman wrote:
> (sorry for my poor English)
> Hello,
> i can make classes at runtime in Python, just like this:
>
> class test: pass
> class myclass:
> def make(self, inherit):
> class temp(inherit): pass
> return temp()
>
> instance = myclass().make(test)
>
> instance is now a class which inherits test... this is a really simple
> example but i need to know because i can't do this in ruby.
> So, is python more dynamic with objects? Isn't ruby good for this kind
> of meta programming?
>
>
Try this
class Test
end
klass = Class.new(Test)
p klass.ancestors #=> [#<Class:.....>, Test, Object, Kernel]
klass is a subclass of Test.
HTH
--
Mark Sparshatt