Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class C1 (object):
- def __init__ (self, title, plus = True):
- self.title = title
- self.plus = plus
- self.acc = 0
- def add (self, x):
- if self.plus:
- self.acc += x
- else:
- self.acc -= x
- def __str__ (self):
- return "C1(%s,%g)" % (self.title,self.acc)
- class C2 (object):
- def __init__ (self, title):
- self.title = title
- self.all = list()
- def add (self, x, pos = None):
- if pos:
- self.all.append(x)
- else:
- self.all.insert(pos,x)
- def __str__ (self):
- return "C2(%s,%s)" % (self.title,self.all)
- import random
- class RandomPair (object):
- def __init__ (self, klass, title, **kwargs):
- self.objects = [klass(title + "#" + str(i), kwargs) for i in range(2)]
- def add (self, *args, **kwargs):
- print args,kwargs
- self.objects[random.randint(0,1)].add(args,kwargs)
- def __str__ (self):
- return "n".join([str(o) for o in self.objects])
- rp1 = RandomPair(C1,"test")
- rp1.add(1)
- rp1.add(2)
- rp2 = RandomPair(C2,"test")
- rp2.add(1)
- rp2.add(2, pos=0)
- TypeError: add() got multiple values for keyword argument 'self'
- self.objects[random.randint(0,1)].add(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement