首先,"/"左倾斜是正斜杠,""右倾斜是反斜杠,可以记为:除号是正斜杠一般来说对于目录分隔符,Unix和Web用正斜杠/,Windows用反斜杠,但是现在Windows
C:\Users\Admin\Desktop\菜单地址
(一)目录中的斜杠们
python读文件需要输入的目录参数,列出以下例子:
path = r"C:Windows emp eadme.txt"
path1 = r"c:windows emp eadme.txt"
path2 = "c:\windows\temp\readme.txt"
path3 = "c:/windows/temp/readme.txt"
打开文件函数open()中的参数可以是path也可以是path1、path2、path3。
path:""为字符串中的特殊字符,加上r后变为原始字符串,则不会对字符串中的" "、" " 进行字符串转义
path1:大小写不影响windows定位到文件
path2:用一个""取消第二个""的特殊转义作用,即为"\"
path3:用正斜杠做目录分隔符也可以转到对应目录,并且在python中path3的方式也省去了反斜杠转义的烦恼