Python Forum

Full Version: Distilling strings using .writelines() and .read()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.