Determining Whether a Directory is Writeable

前端 未结 10 1932
萌比男神i
萌比男神i 2020-12-07 14:44

What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I sh

10条回答
  •  半阙折子戏
    2020-12-07 15:03

    It may seem strange to suggest this, but a common Python idiom is

    It's easier to ask for forgiveness than for permission

    Following that idiom, one might say:

    Try writing to the directory in question, and catch the error if you don't have the permission to do so.

提交回复
热议问题