os.path的一些方法

os.path.basename()

返回一个文件路径的最后一部分

python原厂解释:

Returns the final component of a pathname

例子:

			
>>>a=os.path.basename('/a/b/hello.py')
>>>print a
#输出
hello.py
			
		

os.path.splitext()

splitext 居然是 split extension的缩写

所以这个方法的作用就是,给定一个文件名,将文件扩展和名字分开,返回一个元组,元组的后半部分可能是空

python解释如下:

Split the extension from a pathname.

Extension is everything from the last dot to the end, ignoring leading dots. Returns "(root, ext)"; ext may be empty.

例子:

				
>>>a = os.path.splitext('hello.py')
>>>print a
#输出
('hello','.py')
			
		

os.path.getmtime(filename)

获取该文件最近的修改时间,返回值是从该修改时间到1970.1.1 零时的总秒数(这个太简单,没例子).