os用法可以参考
http://www.cnblogs.com/BeginMan/p/3327291.html
#-*- coding:utf-8 -*-
import os
import sys
import platform
class GetCPUInfo():
def __init__(self):
pass
def get_platform(self):
'''获取操作系统名称及版本号'''
return platform.platform()
def get_version(self):
return platform.version() #获取操作系统版本号,'6.1.7601'
def get_architecture(self):
return platform.architecture() #获取操作系统的位数,('32bit', 'WindowsPE')
def show_os_info(self):
print self.get_platform()
class GetSize():
def __init__(self):
self.filename = [] #保存文件名
print 'you are in', os.getcwd()
if len(sys.argv) < 2: #是否有参数
print 'not arguments'
sys.exit() #没有,退出程序
else:
for arg in sys.argv[1:]:
self.filename.append(arg)
def get_file_size(self):
pass
# print '%-20s %.2fKB' % (self.file , os.path.getsize(self.file)/1024.0) # %-20s 指定占位符宽度(左对齐)
#保存所有文件
def listfile(self):
curdir = os.getcwd() #获得文件当前目录
dir_and_file = os.listdir(curdir) #返回指定目录下的所有文件和目录名
for file in dir_and_file:
if os.path.isfile(file): #检验给出的路径是一个文件
pass
#显示文件大小
def show_file_info(self):
for arg in self.filename:
if os.path.isfile(arg): #判断是否是文件
print '%-20s %.2fKB' % (arg, os.path.getsize(arg)/1024.0)
elif os.path.isdir(arg): #判断是否事目录
print '%s is a dir' % arg
else:
print 'sorry I can\'t find %s' % arg
if __name__ == '__main__':
file_info = GetSize()
file_info.show_file_info()
#cpu_info = GetCPUInfo()
#cpu_info.show_os_info()