python 常用功能錦集

2021-09-23 19:29:43 字數 900 閱讀 5536

環境:linux

程式語言:python

版本:python 2.6.6 (r266:84292, apr 11 2011, 15:52:27)

(1)如何獲取指定檔案的屬主:

def getowner(path2):

import os

import pwd

return pwd.getpwuid(os.stat(path2).st_uid).pw_name

(2)如何遞迴列出指定目錄的所有file(不包括目錄):

def listfiles(path2):

import os

tmp=os.walk(path2)

full_files=

for root,dirs, files in tmp:

for file in files:

return full_files

(3)如何獲取指定檔案的許可權,如755

python**  

def get_power(path3):  

'''''

path3 is directory or regular file

'''import os  

return oct(os.stat(path3)[0])[-3:]  

(4)如何設定許可權

(類似於 chmod 755 /home/user2)

python**  

def chmod(path4,str_power):  

import os  

ifnot os.path.exist(path4):  

return

4#file does not exist

os.chmod(path4,int(str_power,8))  

svn常用功能集

1 更新 2 提交 3 解決衝突 4 從svn中移除 5 打path,一般打乙個測試的path,再打乙個生產中跑的path,等弄好後再合併,這樣方便修改系統,不過這個東西不知道怎麼弄,以後有時間學一下.引用他人的 很多朋友都使用過svn,簡單的提交 更新相信大家也都沒有異議了,今天抽空分享一下svn...

python 常用功能

sintance和type class foo object pass class bar foo pass obj bar isinstance用於判斷,物件是否是指定類的例項 錯誤的 isinstance用於判斷,物件是否是指定類或其派生類的例項 isinstance不精準 print isin...

Python常用功能函式

1.字串反轉 字串反轉 string 字串變數 staticmethod def str reverse string result string 1 return result 2.刪除首尾指定的字元 刪除首尾指定的字元 string 字串變數 rm 要刪除的字元,預設為空格 staticmeth...