Python WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect:

前端 未结 6 529
难免孤独
难免孤独 2020-12-30 22:07

I am new to programming, this is actually my first work assignment with coding. my code below is throwing an error:

WindowsError: [Error 123] The filename,          


        
6条回答
  •  感动是毒
    2020-12-30 22:19

    This is kind of an old question but I wanted to mentioned here the pathlib library in Python3.

    If you write:

    from pathlib import Path
    path: str = 'C:\\Users\\myUserName\\project\\subfolder'
    osDir = Path(path)
    

    or

    path: str = "C:\\Users\\myUserName\\project\\subfolder"
    osDir = Path(path)
    

    osDir will be the same result.

    Also if you write it as:

    path: str = "subfolder"
    osDir = Path(path)
    absolutePath: str = str(Path.absolute(osDir))
    

    you will get back the absolute directory as

    'C:\\Users\\myUserName\\project\\subfolder'
    

    You can check more for the pathlib library here.

提交回复
热议问题