Python : os.chmod 的 mode 之 const variable 意義

今天在改 Project 內一部分程式碼的 Bug, 看到 Team Member 用了 os.chmod 來改系統檔案的權限. 之前沒用過, 因此 mode 的部份怎樣調整就查了一下 API Document. 沒想到 Document 裡也只有 mode 的選項列表, 沒解說 = =

查了一下才發現解讀法, 整理如下 :

S_IRGRP    S_IROTH    S_IRUSR

S_IWGRP    S_IWOTH    S_IWUSR

S_IXGRP    S_IXOTH    S_IXUSR

S_IEXEC = S_IXUSR
S_IWRITE = S_IWUSR
S_IREAD = S_IRUSR

S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP
S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH
S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR

解讀方式如同上述的顏色標示, R = read, W = write, X = execution ; 而 GRP = group, OTH = other, USR = user, 對照到 Unix 系統的權限設定其實就很清楚了. 而後面的更為複雜的標示, 就是前面基本標示的混合而已.

0 意見:

Designed by Posicionamiento Web | Modified by seLain | Bloggerized by GosuBlogger | Blue Business Blogger