Python Forum
Distilling strings using .writelines() and .read()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Distilling strings using .writelines() and .read()
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read module/class from list of strings? popular_dog 1 472 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Trying to understand strings and lists of strings Konstantin23 2 758 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Performance options for sys.stdout.writelines dgrunwal 11 3,110 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  Splitting strings in list of strings jesse68 3 1,759 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  writelines only writes one line to file gr3yali3n 2 2,374 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  read logfile between two specific strings FelixReiter 6 2,891 Jan-04-2021, 02:26 PM
Last Post: FelixReiter
  print a line break in writelines() method leodavinci1990 1 6,449 Oct-12-2020, 06:36 AM
Last Post: DeaD_EyE
  Read strings and numbers in columns from a file suvadip 4 2,880 Aug-11-2020, 09:37 PM
Last Post: suvadip
  Finding multiple strings between the two same strings Slither 1 2,514 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  Strings read from excel don't work? Tibas 0 2,406 Mar-06-2018, 10:37 PM
Last Post: Tibas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020