SHARE
TWEET

Untitled

a guest Jun 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. >>> a = 1
  2. >>> d = {'a':a}
  3. >>> d['a']
  4. 1
  5. >>> a = 2
  6. >>> d['a']
  7. 1
  8.      
  9. >>> a = 1
  10. >>> d = {'a':magical pointer to a}
  11. >>> d['a']
  12. 1
  13. >>> a = 2
  14. >>> d['a']
  15. 2
  16.      
  17. >>> a = mutable_structure(1)
  18. >>> d = {'a':a}
  19. >>> d['a']
  20. 1
  21. >>> a.setValue(2)
  22. >>> d['a']
  23. 2
  24.      
  25. class mutable_structure:
  26.   def __init__(self, val):
  27.     self.val = val
  28.  
  29.   def __repr__(self):
  30.     return self.val
  31.      
  32. a = [1]
  33. d = {'a': a}
  34. a[0] = 2
  35. print d['a'][0]
  36.      
  37. class Mutable(object):
  38.     pass
  39.  
  40. a = Mutable()
  41. a.value = 1
  42.  
  43. d = {'a':a}
  44. a.value = 3
  45.      
  46. class DRefsA(object):
  47.     a = 4
  48.  
  49.     @property
  50.     def d(self):
  51.         return self.a
  52.  
  53.     @d.setter
  54.     def d(self, value):
  55.         self.a = value
  56.      
  57. a = 1
  58. d = {'a': lambda  : a}
  59. print(d['a']()) #output 1
  60. a = 2
  61. print(d['a']()) #output 2
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top