{"id":139772,"date":"2019-03-24T08:24:49","date_gmt":"2019-03-24T00:24:49","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=139772"},"modified":"2019-03-18T10:26:13","modified_gmt":"2019-03-18T02:26:13","slug":"python-test-access","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-test-access.html","title":{"rendered":"Python\u4f7f\u7528os\u6a21\u5757\u68c0\u6d4b\u662f\u5426\u6709\u8bbf\u95ee\u6743\u9650"},"content":{"rendered":"
\u68c0\u9a8c\u6743\u9650\u6a21\u5f0f<\/p>\n
os.access(path,mode)<\/pre>\n<\/div>\n\u53c2\u6570\uff1a<\/p>\n
\u8fd4\u56de\u503c\uff1a \u5982\u679c\u5141\u8bb8\u8bbf\u95ee\u5219\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse\u3002<\/p>\n
\u4f8b\u5b50\uff1a<\/p>\n
import os, sys\r\n\r\n# \u5047\u5b9a \/tmp\/foo.txt \u6587\u4ef6\u5b58\u5728\uff0c\u5e76\u6709\u8bfb\u5199\u6743\u9650\r\n\r\nret = os.access(\"\/tmp\/foo.txt\", os.F_OK)\r\nprint (\"F_OK - \u8fd4\u56de\u503c %s\"% ret)\r\n\r\nret = os.access(\"\/tmp\/foo.txt\", os.R_OK)\r\nprint (\"R_OK - \u8fd4\u56de\u503c %s\"% ret)\r\n\r\nret = os.access(\"\/tmp\/foo.txt\", os.W_OK)\r\nprint (\"W_OK - \u8fd4\u56de\u503c %s\"% ret)\r\n\r\nret = os.access(\"\/tmp\/foo.txt\", os.X_OK)\r\nprint (\"X_OK - \u8fd4\u56de\u503c %s\"% ret)<\/pre>\n