Advertisement
maurobaraldi

Global scope and accessing

Oct 3rd, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. app_name = 'Teste'
  2. app_path = '/home/mauro'
  3.  
  4. class Common(object):
  5.     def __init__(self, path=None):
  6.         self.app_path = path and path or app_path
  7.    
  8.     @property
  9.     def _path_(self):
  10.         return self.app_path
  11.  
  12.     @staticmethod
  13.     def reset_path():
  14.         common.app_path = app_path
  15.  
  16. class Nova(object):
  17.     def path(self):
  18.         print common._path_
  19.  
  20. if __name__ == '__main__':
  21.     common = Common(path='/home/jorge')
  22.     nova = Nova()
  23.     nova.path()
  24.     print app_path
  25.     a = raw_input('Resetando a _path_ da common')
  26.     Common.reset_path()
  27.     print common._path_
  28.     nova.path()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement