讨论数量:
在Python的string前面加上
'r'
, 是为了告诉编译器这个string是个raw string,不要转义 backslash'\'
。 例如,'\n'
在raw string中,是两个字符,\
和n
, 而不会转义为换行符。 由于正则表达式和\
会有冲突,因此,当一个字符串使用了正则表达式后,最好在前面加上'r'
。
src = r"C:/Users/ 黄伟 / Desktop/publish/os 模块 /test_shutil_a\a.xlsx"
dst = r"C:\Users\ 黄伟 \Desktop\publish\os 模块 \test_shutil_b\aa.xlsx"
等同
src = "C:/Users/ 黄伟 / Desktop/publish/os 模块 /test_shutil_a\\a.xlsx"
dst = "C:\\Users\\ 黄伟 \\Desktop\\publish\\os 模块 \\test_shutil_b\\aa.xlsx"
等同