Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. def read_config(parameter):
  2. """get the value of a configuration parameter"""
  3. para_list = parameter.split(".")
  4. config = Config()
  5. obj = config
  6. response = None
  7. for i in range(len(para_list)):
  8.  
  9. # Check to see if they are using subscripts
  10. p = re.compile('\[(.*?)\]')
  11. m = p.search(para_list[i])
  12.  
  13. if bool(p.search(para_list[i])) == True:
  14. # Get the base item of the subscript first
  15. item = re.sub(r'\[.*?\]', '', para_list[i])
  16.  
  17. response = getattr(obj, item)
  18.  
  19.  
  20. if type(obj) == list:
  21. # Get the subscript object
  22. print len(m.group(1))
  23. if len(m.group(1)) == 0:
  24. obj = response[0]
  25. else:
  26. obj = response[int(m.group(1))]
  27. else:
  28. print item
  29. response = getattr(obj, item)
  30. obj = response
  31.  
  32.  
  33. else:
  34. response = getattr(obj, para_list[i])
  35. obj = response
  36. return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement