class Book():
def __init__(self,ISBN,Ftile,Author,Publisher):
self.ISBN = ISBN
self.Ftile = Ftile
self.Author = Author
self.Publisher = Publisher def show(self):
print(self.ISBN,self.Ftile,self.Author,self.Publisher) class BookList():
def __init__(self):
self.books = [] def show(self):
print(self.ISBN, self.Ftile, self.Author, self.Publisher)
for i in self.books:
self.show() def __insert(self,s):
i = 0
while(i<len(self.books) and s.ISBN > self.books[i]):
i=i+1
self.books.insert(i,s)#指定位置添加一个元素
print("ok") def __update(self,s):
i = 0
while(i<len(self.books) and s.ISBN != self.books[i]):
i=i+1
if(s.ISBN==self.books[i]):
del self.books[i]
self.books.insert(i,s)
print("-- update @ ok --")
else:
print("--error--") def __delete(self):
while(i<len(self.books) and s.ISBN != self.books[1]):
i=i+1
if(s.ISBN ==self.books[i]):
del self.books[i]
print("-- delete @ ok --")
else:
print("--error--") def insert(self):
ISBN = input('ISBN:')
Ftile = input('Ftile:')
Author = input('Author:')
Publisher = input('Publisher:')
if (ISBN!='' and Ftile!=''):
self.__insert(Book(ISBN,Ftile,Author,Publisher))
else:
print("--ISBN/Ftile^error--") def update(self):
ISBN = input('ISBN:')
Ftile = input('Ftile:')
Author = input('Author:')
Publisher = input('Publisher:')
if (ISBN != '' or Ftile != '' or Author!='' or Publisher!=''):
self.__update(Book(ISBN, Ftile, Author, Publisher))
else:
print("---error---") def delete(self):
ISBN = input('ISBN:')
Ftile = input('Ftile:')
Author = input('Author:')
Publisher = input('Publisher:')
if (ISBN != '' or Ftile != '' or Author != '' or Publisher != ''):
self.__delete(Book(ISBN, Ftile, Author, Publisher))
else:
print("---error---") def scan(self):
while True:
s = input(">>>")
if s=='show':
self.show()
elif s=='insert':
self.insert()
elif s=='update':
self.update()
elif s=='delete':
self.delete()
elif s=='exit':
break
else:
print(" ---- Error ---- ")
return 0
self.File()
#print(self.books) 》》》》[<__main__.Book object at 0x0000020B3A08CFD0>] def File(self):
f = open('jiaocai.txt','wt+',encoding = 'utf-8')
for i in self.books:
f.write(i.ISBN+'\n')
f.write(i.Ftile+'\n')
f.write(i.Author+'\n')
f.write(i.Publisher+'\n')
#books = self.books
#f.write(str(books))#不可用
f.close() Bl=BookList()
Bl.scan()
#print(BookList.books)

最新文章

  1. Maven学习
  2. 适当使用enum做数据字典 ( .net c# winform csharp asp.net webform )
  3. ubuntu下crontab编辑方法的设定
  4. 新浪微博客户端(35)-使用NSMutableAttributedString实现多行文本的效果
  5. 设置Tomcat编码
  6. Python: 收集所有命名参数
  7. js数组判断是否含有某一个元素
  8. php 配置本地自定义域名
  9. 利用VHD虚拟文件加密自己的个人信息
  10. Apache启用性能优化——启用Gzip,JS压缩
  11. postgres数据库中的数据转换
  12. the Linux Kernel: Traffic Control, Shaping and QoS
  13. Hashtable映射数据库字段
  14. Java语言开发环境搭建
  15. CTF---密码学入门第六题 古典密码
  16. Android WebView编程的那些坑(一)
  17. 让你的代码量减少3倍!使用kotlin开发Android(一)
  18. 【Keil5 MDK】fromelf工具的基本用法(fromelf --help)
  19. luogu P2387 [NOI2014]魔法森林
  20. mysql: [ERROR] unknown variable &#39;datadir=/var/lib/mysql&#39;问题

热门文章

  1. 3.文档视图:从gui分割状态
  2. 浅谈assert()函数的用法
  3. jQuery CSS 操作
  4. [学习笔记]信号基本概念(中断和信号)/名称及常用信号/信号处理/signal函数实践
  5. Android之悬浮窗口实现(WindowManager)
  6. excel导出工具
  7. HTML完全使用详解 PDF扫描版​
  8. HTTP 协议 -- 基础
  9. win10下安装配置mysql-8.0.13--实战可用
  10. iOS工程师 - 简历