How to get an absolute file path in Python

前端 未结 9 1319
孤城傲影
孤城傲影 2020-11-22 11:53

Given a path such as \"mydir/myfile.txt\", how do I find the file\'s absolute path relative to the current working directory in Python? E.g. on Windows, I might

9条回答
  •  日久生厌
    2020-11-22 12:17

    if you are on a mac

    import os
    upload_folder = os.path.abspath("static/img/users")
    

    this will give you a full path:

    print(upload_folder)
    

    will show the following path:

    >>>/Users/myUsername/PycharmProjects/OBS/static/img/user
    

提交回复
热议问题