Quantcast
Channel: User Ciprian Tarta - Stack Overflow
Viewing all articles
Browse latest Browse all 31

Answer by Ciprian Tarta for Is there any Python equivalent to partial classes?

$
0
0

You can do this with decorators like so:

class Car(object):    def start(self):        print 'Car has started'def extends(klass):    def decorator(func):        setattr(klass, func.__name__, func)        return func    return decorator#this can go in a different module/file@extends(Car)def do_start(self):    self.start()#so can thiscar = Car()car.do_start()#=> Car has started

Viewing all articles
Browse latest Browse all 31

Latest Images

Trending Articles





Latest Images