the following code ends in an exception: import re pattern = 'Sottoscrizione unica soluzione' mylines = [] # Declare an empty list. with open ('tmp.txt', 'rt') as myfile: # Open tmp.txt for reading text. for myline in myfile: # For each line in the file, mylines.append(myline.rstrip('\n')) # strip newline and add to list. for element in mylines: # For each element in the list, # print(element) match = re.search(pattern, element) s = match.start() e = match.end() print(element[s:e])
F:\October20-2019-RECOVERY\Unicredit_recovery\tmp_re_search>c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\python.exe search_0.py Traceback (most recent call last): File "search_0.py", line 10, in <module> s = match.start() AttributeError: 'NoneType' object has no attribute 'start' any help? Thanks -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 -- https://mail.python.org/mailman/listinfo/python-list