Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ini_regexen_dicts import *
- import re
- class ConfigParser:
- def __init__(self, filename="config.ini"):
- f = file(filename)
- lines = f.readlines()
- f.close()
- # Remove the '\n's from the end of each line
- lines = [line[0:line.__len__()-1] for line in lines]
- contents = []
- content = {}
- # Compile the regexen
- patterns = {}
- for pattern in pattern_strings:
- patterns.update(pattern: re.compile(pattern_strings[pattern], re.VERBOSE))
- # Get the content in each line
- for line in lines:
- for pattern in patterns:
- # Match each pattern to the current line
- match = patterns[pattern].search(line)
- if match:
- content.update({pattern: match.groups()})
- contents += (content.items())
- content = {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement