Windows path in Python

后端 未结 5 1722
悲哀的现实
悲哀的现实 2020-11-21 04:18

What is the best way to represent a Windows directory, for example \"C:\\meshes\\as\"? I have been trying to modify a script but it never works because I can\'t

5条回答
  •  渐次进展
    2020-11-21 05:12

    Use the os.path module.

    os.path.join( "C:", "meshes", "as" )
    

    Or use raw strings

    r"C:\meshes\as"
    

    I would also recommend no spaces in the path or file names. And you could use double backslashes in your strings.

    "C:\\meshes\\as.jpg"
    

提交回复
热议问题