pymysql There's a special escape method in , The import syntax is as follows ：
from pymysql import escape_string
When you use it, you just need to escape the specific string first , Then insert the escaped string into the database , Examples of escape methods are as follows ：
s = r'D:\ Video tutorial \ big data \【 Let's have a class 】 Liao Xuefeng · 2019 Big data analysis \ Introduction ' es = escape_string(s)
If it will contain special characters
\ Is inserted directly into MySQL In the database , There may be
\ Loss or other problems .
If you insert it directly
r'D:\ Video tutorial \ big data \【 Let's have a class 】 Liao Xuefeng · 2019 Big data analysis \ Introduction ', What is actually stored in the database is
D: Video tutorial big data 【 Let's have a class 】 Liao Xuefeng · 2019 Let's start big data analysis , And by
escape_string Methods are escaped and then inserted into the database , Then the actual storage effect is what we want .
We insert the transferred string into the database , Then read from the database and save it to Python There is no need to reverse escape the memory variable of , Because it will help us automatically reverse the escape .
As shown in the actual case below , Read from the database is a tuple , Later, the string in the tuple is used for some operations （ Such as printing operation ） Will automatically perform a reverse escape operation when , So we don't have to do extra anti escape
About Python In the path of the string standard writing can refer to ：Python take str Convert to path type ？ Test cases in , Through the test case to speculate , After all, practice is the only test of truth .