How to get the home directory in Python? [duplicate]

扶醉桌前 提交于 2019-11-26 05:40:29
dcolish

You want to use os.path.expanduser. This will ensure it works on all platforms

from os.path import expanduser
home = expanduser("~")

If you're on Python 3.5+ you can use pathlib.Path.home():

from pathlib import Path
home = str(Path.home())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!