Python Forum
Distilling strings using .writelines() and .read() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Distilling strings using .writelines() and .read() (/thread-19357.html)



Distilling strings using .writelines() and .read() - tedie - Jun-24-2019

Hi all,
I am experiencing a phenomena that I'm unable to explain to date.

I have a long string that I'm passing to a function, and in that function I am using a regex substitution to clean the string of white spaces, carriage returns, and certain special characters.

If I pass the string directly and then run the regex, the regex gives me an output that I am not expecting. (incorrect)
If I pass the string, then write it to a file, then read the file, then run the regex, the string can properly be parsed by the regex. (correct)
If I write the string to a file, read the file, then pass the string, then run the regex, the string can be parsed by the regex. (correct)

It matters not in which subroutine the string is written to file and then read.
It only seems to matter that it has been "distilled" via .writelines() and .read()

Obviously, I'd rather not have to write the string to a file, then read the file, just to parse my string.
What am I not understanding here?
Please let me know if you require further explanation.
Thanks,
-tedie


RE: Distilling strings using .writelines() and .read() - micseydel - Jun-24-2019

It would help us to help you if you provided code. Ideally it would be 5-10 lines that reproduce your issue while excluding extraneous details not related to the question.