Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def read_config(parameter):
- """get the value of a configuration parameter"""
- para_list = parameter.split(".")
- config = Config()
- obj = config
- response = None
- for i in range(len(para_list)):
- # Check to see if they are using subscripts
- p = re.compile('\[(.*?)\]')
- m = p.search(para_list[i])
- if bool(p.search(para_list[i])) == True:
- # Get the base item of the subscript first
- item = re.sub(r'\[.*?\]', '', para_list[i])
- response = getattr(obj, item)
- if type(obj) == list:
- # Get the subscript object
- print len(m.group(1))
- if len(m.group(1)) == 0:
- obj = response[0]
- else:
- obj = response[int(m.group(1))]
- else:
- print item
- response = getattr(obj, item)
- obj = response
- else:
- response = getattr(obj, para_list[i])
- obj = response
- return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement