'new' module deprecation in python2.6

Scott David Daniels Scott.Daniels at Acm.Org
Sat Nov 29 13:07:17 EST 2008


David Pratt wrote:
> ...
> import new
> 
> class FirstBase(object):
>     foo = 'bar'
>     biz = 'baz'
> 
> class SecondBase(object):
>     bla = 'blu'
>     buz = 'brr'
> 
> attr = {
>     'fiz': 'An attribute', 'fuz': 'Another one'}
> 
> Test = new.classobj(
^^^ replace with:
   Test = type(
>     'Test', (FirstBase, SecondBase), attr)
> 
> class MyNewClass(Test):
>     pass
> 
> a = MyNewClass()
> 
> print a.foo, a.buz, a.fiz, type(a)
 > ...

It's really that simple.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list