The variables defined within a context can be accessed outside of the cotext.
The context is used to apply automatic operations.
- Python Interpreter will escape special characters only once !
\n ---> r"\n"
Unicode Escape Characters
Python will treat \x0343 as unicode string when printing to console or write to text file.
Python will treat \x0343 as ASCII characters when printing to console or write to text file (!!! Due to The Escape Only Once Principle)
- Unnecessary Escapes can be removed by line = line.replace(r"\", "\")
Python Json String "()"
(1,2,3) ---> String Repr: "(1, 2, 3)"
Comment: It looks like you need to flush stdout periodically (e.g. sys.stdout.flush()). In my testing Python doesn't automatically do this even with print until the program exits.
You can run Python with the -u flag to avoid output buffering
2. 解决办法之二： sys.stdout.flush()