首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python 惯用功能锦集

2013-01-04 
python 常用功能锦集环境:linux编程语言:python版本:Python 2.6.6 (r266:84292, Apr 11 2011, 15:52:27)?(

python 常用功能锦集

环境: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:

? ? ? ? ? ? ? ? ? ? ? ? full_files.append(os.path.join(root,file))

? ? ? ? return full_files

?

?

(3)如何获取指定文件的权限,如755

def chmod(path4,str_power):import osif not os.path.exist(path4):return 4 #file does not existos.chmod(path4,int(str_power,8))
?

?

?

?

?

热点排行