Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. class C1 (object):
  2. def __init__ (self, title, plus = True):
  3. self.title = title
  4. self.plus = plus
  5. self.acc = 0
  6.  
  7. def add (self, x):
  8. if self.plus:
  9. self.acc += x
  10. else:
  11. self.acc -= x
  12.  
  13. def __str__ (self):
  14. return "C1(%s,%g)" % (self.title,self.acc)
  15.  
  16. class C2 (object):
  17. def __init__ (self, title):
  18. self.title = title
  19. self.all = list()
  20.  
  21. def add (self, x, pos = None):
  22. if pos:
  23. self.all.append(x)
  24. else:
  25. self.all.insert(pos,x)
  26.  
  27. def __str__ (self):
  28. return "C2(%s,%s)" % (self.title,self.all)
  29.  
  30. import random
  31. class RandomPair (object):
  32. def __init__ (self, klass, title, **kwargs):
  33. self.objects = [klass(title + "#" + str(i), kwargs) for i in range(2)]
  34.  
  35. def add (self, *args, **kwargs):
  36. print args,kwargs
  37. self.objects[random.randint(0,1)].add(args,kwargs)
  38.  
  39. def __str__ (self):
  40. return "n".join([str(o) for o in self.objects])
  41.  
  42. rp1 = RandomPair(C1,"test")
  43. rp1.add(1)
  44. rp1.add(2)
  45. rp2 = RandomPair(C2,"test")
  46. rp2.add(1)
  47. rp2.add(2, pos=0)
  48.  
  49. TypeError: add() got multiple values for keyword argument 'self'
  50.  
  51. self.objects[random.randint(0,1)].add(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement