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