Jan-20-2024, 02:47 AM
(This post was last modified: Jan-20-2024, 03:26 AM by deanhystad.)
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()
deanhystad write Jan-20-2024, 03:26 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.