import re
with open('source.txt', 'r') as file:
inputText = file.readlines()
myDict = {}
for line in range(len(inputText)):
# Have a Text line
if inputText[line].lstrip().startswith('.Text'):
# Get the key with regular expression
key = re.search('"(.+?)"', inputText[line]).group(1)
value = re.search('"(.+?)"', inputText[line + 1]).group(1)
myDict[key] = value
print(myDict)
re Error:-
value = re.search('"(.+?)"', inputText[line + 1]).group(1) AttributeError: 'NoneType' object has no attribute 'group'
For more information, refer to:-
Python to create a find-replace dictionary from a word vba macro
Previous questions also do have answers. But i dont know re library.