004 classmates subject
为什么80%的码农都做不了架构师?>>>
look code
# Filename: classmates2.py
import os,pickleclass Friend:def __init__(self,name,age,phone):self.name=nameself.age=ageself.phone=phonedef __str__(self):return '%s %d %s'%(self.name,self.age,self.phone)class Main:flist=[]# data listisChange=False# tip change operatingisStart=True# tip startsource='classmates'# source data namedef __init__(self):hasData=os.path.isfile(Main.source+'.data')hasTxt=os.path.isfile(Main.source+'.txt')if hasData:Main.readFile(self,Main.source+'.data')elif hasTxt:Main.readTxtFile(self,Main.source+'.txt')Main.save(self)else:Main.writeFile(self,Main.source+'.data')Main.isStart=False# Startdef start(self):Main.readme(self)while True:cmd=input('Command:')if cmd in ['exit','quit','q']:break;elif cmd in ['show','sh']:Main.show(self)elif cmd.startswith('find'):Main.show(self,Main.find(self,cmd.split(',')[1:]))elif cmd.startswith('add'):Main.add(self,cmd.split(',')[1:])elif cmd.startswith('dele'):Main.delete(self,cmd.split(',')[1:])elif cmd in['clear','clr','c']:Main.clear(self)elif cmd in ['save','sa']:Main.save(self)elif cmd.startswith('export'):Main.export(self)else:print('Please try again!')print('exit')# Show datadef show(self,data=None):if data==None:data=Main.flist[:]if len(data)==0:print('no result')else:if len(data)==1:print(data[0])else:print('list size %d:'%len(data))for item in data:print(item)# Find data list by keysdef find(self,keys):if len(keys)==0:return []else:tmplist=[]for fri in Main.flist:if (fri.name in keys) or (str(fri.age) in keys) or (fri.phone in keys):tmplist.append(fri)return tmplist# Add data to flistdef add(self,vals):if len(vals)==3:Main.flist.append(Friend(vals[0],int(vals[1]),vals[2]))Main.isChange=Trueif not Main.isStart:print('%s add success!'%vals[0])else:print('the add command arguments is error, it must following 3 argument.')# Delete data by keysdef delete(self,keys):tmplist=Main.find(self,keys)if len(tmplist)==0:print('no reslt')else:Main.flist=[i for i in Main.flist if not (i in tmplist)]Main.isChange=Trueprint('has delete')Main.show(self,tmplist)def clear(self):if len(Main.flist)==0:print('no need')else:Main.flist.clear()Main.isChange=Trueprint('clear success')# Save data to localdef save(self):if Main.isChange:Main.isChange=FalseMain.writeFile(self,Main.source+'.data')if not Main.isStart:print('save success')else:print('No change')# Write informat to the path filedef writeFile(self,path):file=open(path,'wb')pickle.dump(Main.flist,file)file.close()# Read the path filedef readFile(self,path):file=open(path,'rb')Main.flist=pickle.load(file)file.close()# Read the path text filedef readTxtFile(self,path):file=open(path,encoding='utf-8')line=file.readline()while True:line=file.readline()if len(line)==0:breakMain.add(self,line.strip().split(' '))# Export a text filedef export(self,path=None):if not Main.isChange:print('No change')returnif path==None:path=Main.source+'.txt'file=open(path,'w',encoding='utf-8')file.write(Main.parseStr(self))file.close()os.system(path)print('exprot success')# Parse list to strdef parseStr(self):rst='list:\n'for fri in Main.flist:rst+=str(fri)+'\n'return rst# User's manualdef readme(self):print('You can input up command:')print(' exit/quit/q:exit the program')print(' show/sh:show the list')print(' find:find list by keys')print(' add:add new friend information')print(' dele:delete by keys')print(' clear/clr/c:clear the list')print(' save/sa:save the result')print(' export:export a text file and view the file')passmain=Main()
main.start()
转载于:https://my.oschina.net/tunie/blog/137886
004 classmates subject相关推荐
- 基础004:R语言数据处理和变换——dplyr
dplyr 背景简介 安装和数据准备 常用函数 变量筛选select 数据筛选filter 排序arrange 创建新变量mutate 本文"植物微生物组"公众号原创,ID: pl ...
- Book REPORT:Subject To Change
Book REPORT:Subject To Change 曹竹 Sooner or later, every developer out there gets sick of the long ho ...
- 自签名证书说明——自签名证书的Issuer和Subject是一样的。不安全的原因是:没有得到专业SSL证书颁发的机构的技术支持?比如使用不安全的1024位非对称密钥对,有效期设置很长等...
一般的数字证书产品的主题通常含有如下字段: 公用名称 (Common Name) 简称:CN 字段,对于 SSL 证书,一般为网站域名:而对于代码签名证书则为申请单位名称:而对于客户端证书则为证书申请 ...
- 记一次TrustAnchor with subject异常解决
新部署的ARM环境报如下异常(更新了JDK到1.8.0.273): io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshak ...
- 【LeetCode】004 Median of Two Sorted Arrays 两个排序数组合并后的中位数
题目:LeetCode 004 Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m an ...
- 使用 Rx 中预定义的 Subject
看到一幅有趣的关于 Rx 学习的图,想知道学习 Rx 的学习曲线?不,是峭壁! 我们可以直接通过 Rx 的 Observer 来创建 Observable 对象. 但是,使用这种方式往往比较复杂,在特 ...
- 004 Android之其他控件
文章目录 ListView ListView常用属性 ListView基本使用 ListView动态插入数据 ListView实现图文混排 Adapter Adapter(适配器种类) 自定义Adap ...
- 004 两种方法找寻路call
文章目录 关于寻路call 通过参数找寻路call CE搜索寻路目的地坐标 通过参数定位寻路call 寻路call参数分析 寻路call代码测试 寻路状态找寻路call 搜索寻路标志位 通过寻路标志位 ...
- shiro的登录 subject.login(token)中执行逻辑和流程
文章目录 官方文档中的介绍 使用subject.login的登录场景: DelegatingSubject实现类中的login方法: DefaultSecurityManager Authentica ...
最新文章
- 【硅谷牛仔】优步CEO,最倒霉的成功创业者 -- 特拉维斯·卡兰尼克
- 5 个关于 API 中日期和时间设计规则
- Coursera吴恩达《序列模型》课程笔记(2)-- NLP Word Embeddings
- 前端基础——day1
- 高效万进制——蓝桥杯|HDOJ 1002 大数加法——30行代码AC
- spring框架(六)之拦截器
- ☆【CodeForces - 764C】Timofey and a tree (思维题,树的性质)
- linux配置mysql数据库_Linux下配置mysql数据库
- ROS入门笔记(十二):动作编程 (C++)
- leaflet地图原理_基于 leaflet 的标注绘图
- 面向云数据库,超低延迟文件系统PolarFS诞生了 1
- 【面试题37】两个链表的第一个公共结点
- 在希望的田野上--生物柴油(Biodiesel)光明的未来
- JAVA DES加密解密代码范例
- Atitit 安全登录退出管理法v3 tbb.docx 目录 1.1. 未持有效出入边界票据。。校验票据有效性	1 1.2. 从事与票据种类不符的活动的	2 1.3. 数据为数字的应该校验数字	2
- 跨浏览器共享数据_不懂浏览器安全,被老板邀请爬山?
- 00004 死亡阴影.0001:配置文件的Unity包与修改
- SMOTE算法原理及程序python(新手版)
- 临湘东经子午线经度_经纬度与中央子午线查询表(精确到县级)
- leetcode LCP3 机器人大冒险(C++)
热门文章
- java 数据库连接不上_真心求助用java连接数据库时为什么总是连接不上
- 2款在线FM音乐聚合播放PHP源码 带搜索
- .NET实现之(自动更新
- JQuery中使用Ajax赋值给全局变量失败异常的解决方法,jqueryajax
- 简单的php代理 Simple PHP Proxy
- UITableView 系列四 :项目中行的操作 (添加移动和删除)(实例)
- UITableView 系列一 :基本使用方法 (显示,删除,添加图片,添加样式等) (实例)...
- Makefile.am和makefile.in生成Makefile
- Go 标准库: io
- Linux shell 下的复制和粘贴(Copy Paste Operation on Linux shell)