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