在python中路径含有空格的解决方法

在python中路径含有空格的解决方法
1.Application.filename=tkinter.filedialog.askopenfilename(filetypes=[('docx|doc格式','*.docx;*.doc')])  #获取的docx文件路径
  通过函数tkinter.filedialog.askopenfilename()获取的路径使用/做分隔符
  而word.Documents.Open(路径)中的路径使用\为分隔符
2.解决方法:
            s = Application.filename.split("/")#解决文件夹及文件路径含有空格。原因是tkinter.filedialog.askopenfilename获取的路径(Application.filename)分隔符是/而日文系统 \.
            path_test = ''
            for i in s:
                 path_test = path_test + i + '\\\\' #此处无法使用r'路径格式'因此在上面  使用'\\\\'格式处理
                
                
            path_test1 = path_test[0:-2]
            path_test2 = path_test1
     

猜你喜欢

转载自blog.csdn.net/daihuibing389/article/details/79486434