Python Programming Notes

Language Features

  1. Context
    The variables defined within a context can be accessed outside of the cotext.
    The context is used to apply automatic operations.

Escape Depth

  1. Python Interpreter will escape special characters only once !
    \n ---> r"\n"

  2. 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)

  1. Unnecessary Escapes can be removed by line = line.replace(r"\", "\")

Python Json String "()"

(1,2,3) ---> String Repr: "(1, 2, 3)"

Nohup下输出重定向失效的问题

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
1. 解决办法之一:加-u
2. 解决办法之二: sys.stdout.flush()