Finding the user's “My Documents” path

后端 未结 4 515
生来不讨喜
生来不讨喜 2020-11-28 11:14

I have this small program and it needs to create a small .txt file in their \'My Documents\' Folder. Here\'s the code I have for that:

textfile=open(\'C:\\Us         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 11:50

    Use os.path.expanduser(path), see http://docs.python.org/library/os.path.html

    e.g. expanduser('~/filename')

    This works on both Unix and Windows, according to the docs.

    Edit: forward slash due to Sven's comment.

提交回复
热议问题