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)

python_案例综合:教材记录管理的更多相关文章

  1. Python_案例_斐波那契数

    方法一: 1 #!/usr/bin/python3 2 3 # Fibonacci series: 斐波纳契数列 4 # 两个元素的总和确定了下一个数 5 a, b = 0, 1 6 while b ...

  2. Mybatis(综合案例)

    MyBatis本是apache的一个开源项目iBatis,2010年这个项目有Apache software foundation 迁移到了Google code,并改名MyBatis.2013年11 ...

  3. python_文件操作代码实例

    """提示:代码中的内容均被注释,请参考,切勿照搬""" 1 #文件的打开和关闭 ''' 文件对象 = open('文件名','使用方式') ...

  4. python_文件的打开和关闭

    文件对象 = open('文件名','使用方式')rt:读取一个txt文件wt: 只写打开一个txt文件,(如果没有该文件则新建该文件)会覆盖原有内容at:打开一个txt文件,并从文件指针位置追加写内 ...

  5. 企业Shell面试题及企业运维实战案例(三)

    1.企业Shell面试题1:批量生成随机字符文件名案例 使用for循环在/oldboy目录下批量创建10个html文件,其中每个文件需要包含10个随机小写字母加固定字符串oldboy,名称示例如下: ...

  6. Mybatis

    Mybatis MyBatis本是apache的一个开源项目iBatis,2010年这个项目有Apache software foundation 迁移到了Google code,并改名MyBatis ...

  7. 03-Vue入门系列之Vue列表渲染及条件渲染实战

    3.1. 条件渲染 有时候我们要根据数据的情况,决定标签是否进行显示或者有其他动作.最常见的就是,表格渲染的时候,如果表格没有数据,就显示无数据.如果有数据就显示表格数据. Vue帮我们提供了一个v- ...

  8. 王家林 大数据Spark超经典视频链接全集[转]

    压缩过的大数据Spark蘑菇云行动前置课程视频百度云分享链接 链接:http://pan.baidu.com/s/1cFqjQu SCALA专辑 Scala深入浅出经典视频 链接:http://pan ...

  9. Web服务器(Apache)虚拟主机的配置

    一.定义    所谓虚拟主机是指在一台服务器里运行几个网站,提供WEB.FTP.Mail等服务.    二.虚拟主机的实现方法有三种:    基于IP的方法,基于主机名的方法和基于端口的法官法.    ...

随机推荐

  1. Entity Framework Tutorial Basics(22):Disconnected Entities

    Disconnected Entities: Before we see how to perform CRUD operation on disconnected entity graph, let ...

  2. HttpServletRequest和ServletRequest的区别.RP

    问题: 请问HttpServletRequest和ServletRequest的区别? 回答: servlet理论上可以处理多种形式的请求响应形式 http只是其中之一 所以HttpServletRe ...

  3. AbstractBootstrap的研读

    AbstractBootstrap是一个工具类,用来配置和启动Channel的,下面看下AbstractBootstrap的类继承,ServerBootstrap用于启动ServerChannel的, ...

  4. Android之九宫格解锁的实现

        <ignore_js_op>                                                  下面是最重要的那个LocusPassWordView ...

  5. Tomcat 集群 + Redis Session 共享出现 Session 瞬间失效问题

    写在前面的话 写这篇博客出于公司最近要迁移到新的云上面且对之前的资源,架构做一个升级. 本来是一个不大的项目,旧环境旧一个 TOMCAT 跑起来,不过出于高可用考虑,新环境决定使用 TOMCAT 集群 ...

  6. myql 服务启动不了怎么办

    今天,不小心手动将mysql 服务停掉后,怎么也启动不了,后面查了半天 ,终于知道要先将任务管理器里的mysql.exe 先Kill掉,然后可以启动了,记录一下

  7. D - Back and Forth(模拟)

    Problem Statement Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis point ...

  8. [SinGuLaRiTy] NOIP模拟赛(TSY)-Day 2

    [SinGuLaRiTy-2033] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved.                              ...

  9. Kubernetes 集群部署(1) -- 自签 TLS 证书

    集群功能各模块功能描述: Master节点:主要由四个模块组成,APIServer,schedule, controller-manager, etcd APIServer: APIServer负责对 ...

  10. kuangbin专题16D(next求最小循环节)

    题目链接: https://vjudge.net/contest/70325#problem/D 题意: 给出一个循环字符串, 可以在两端添加任意字符, 问最少添加多少字符可以使循环字符串变成周期循环 ...