Jan-20-2024, 02:47 AM
python 3.12.1 Windows 11 command prompt (cmd)
TURN THIS:
this85_e1.txt
the other38_4e.asc
INTO THIS:
this
the other
This was working a few days ago and I thought I was running the
same code today. But now I get this error
File "C:\Users\phill\Documents\python\re_search_pub.py", line 9, in <module>
ln = line[0:pos.start()]
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'start'
I did check out https://docs.python.org/dev/library/re.html
But can't figure out why [pos] is (now) a 'NoneType'
MY CODE:
TURN THIS:
this85_e1.txt
the other38_4e.asc
INTO THIS:
this
the other
This was working a few days ago and I thought I was running the
same code today. But now I get this error
File "C:\Users\phill\Documents\python\re_search_pub.py", line 9, in <module>
ln = line[0:pos.start()]
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'start'
I did check out https://docs.python.org/dev/library/re.html
But can't figure out why [pos] is (now) a 'NoneType'
MY CODE:
import re ln = "" pos = 0 output_file = open("bare.txt", "w") lines = open("filelist.asc", "r").readlines() for line in lines: pos = re.search(r"\d\d_\w\w", line) ln = line[0:pos.start()] output_file.write(ln + '\n') output_file.close()