fork download
  1. # your code goes here
  2.  
  3. class A1:
  4. def __init__(self, a, b):
  5. self.a = a
  6. self.b = b
  7. self.c = 10
  8. def pnt1(self):
  9. for prop in dir(self):
  10. if prop.startswith('__') and prop.endswith('__'):
  11. continue
  12. if hasattr(self, prop):
  13. print(prop)
  14. print(getattr(self, prop))
  15. print("A1")
  16.  
  17. class A2:
  18. def __init__(self, a, b):
  19. self.a = a
  20. self.b = b
  21. self.c = 12
  22. self.d = 34
  23. def pnt2(self):
  24. for prop in dir(self):
  25. if prop.startswith('__') and prop.endswith('__'):
  26. continue
  27. if hasattr(self, prop):
  28. print(prop)
  29. print(getattr(self, prop))
  30. print("A2")
  31.  
  32.  
  33. a = A1(5, 6) # a = 5, b= 6, c = 10
  34. b = A2(1, 2) # a = 1, b = 2, c = 12, d = 10
  35.  
  36. def copy_properties(source, target):
  37. for prop in dir(source):
  38. if prop.startswith('__') and prop.endswith('__'):
  39. continue # Skip built-in properties
  40. if hasattr(target, prop):
  41. print('LOL :')
  42. print(prop)
  43. setattr(target, prop, getattr(source, prop))
  44.  
  45. print("CP")
  46. a.pnt1()
  47. b.pnt2()
  48. copy_properties(a, b)
  49. b.pnt2()
  50. # b.pnt1()
  51. print(b.d)
  52.  
Success #stdin #stdout 0.04s 9712KB
stdin
Standard input is empty
stdout
a
5
b
6
c
10
pnt1
<bound method A1.pnt1 of <__main__.A1 object at 0x14b84f13bd00>>
A1
a
1
b
2
c
12
d
34
pnt2
<bound method A2.pnt2 of <__main__.A2 object at 0x14b84f13b550>>
A2
LOL :
a
LOL :
b
LOL :
c
CP
a
5
b
6
c
10
d
34
pnt2
<bound method A2.pnt2 of <__main__.A2 object at 0x14b84f13b550>>
A2
34