python本地文件
2016-04-30 09:02
387 查看
os用法可以参考
http://www.cnblogs.com/BeginMan/p/3327291.html
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()
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法