I have a text file (*.txt) which displays as plain text when opened in notepad. When i attempt to read the file into python:
with open(Working_File,'r') as WorkTXT:
WorkTXT_Lines = WorkTXT.readlines()
WorkTXT.close()
My script then fails because the text is being converted into something else. I can manually test what's in the list using the console:
In[51]: WorkTXT_Lines[4]
Out[51]: "\x00T\x00h\x00e\x00 \x00A\x00c\x00q\x00.\x00 \x00M\x00e\x00t\x00h\x00o\x00d\x00'\x00s\x00 \x00I\x00n\x00s\x00t\x00r\x00u\x00m\x00e\x00n\x00t\x00 \x00P\x00a\x00r\x00a\x00m\x00e\x00t\x00e\x00r\x00s\x00 \x00f\x00o\x00r\x00 \x00t\x00h\x00e\x00 \x00R\x00u\x00n\x00 \x00w\x00e\x00r\x00e\x00 \x00:\x00 \x00\r\x00\n"
If i open the original text file and copy-paste the text into a new text file then run it seems to pick up actual text and the script works correctly. That does not help though as i am parsing through hundreds of text files generated from a lab instrument.
Any help is appreciated, even something like an OS command to alter the text file.
Edit - was able to solve the issue after being led in the correct direction. The io module is able to decode the text file and "read as text (rt)"
import io
with io.open(Working_File,'rt') as WorkTXT:
WorkTXT_Lines = WorkTXT.readlines()
WorkTXT.close()