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. poj1769 Minimizing maximizer

    传送门 题目大意 给你m个机器,n个数,每个机器可以给n个数的某一段排序,求最少使用几个机器,保证可以把这个n个数排好序 分析 我们可以想到dpij表示考虑前i个机器让最大的数到达点j至少需要使用多少 ...

  2. SPOJ GSS7 - Can you answer these queries VII

    板的不能再板,链剖+线段树或者是LCT随便维护. 感觉唯一要注意的是跳链的时候要对$x$向上跳和$y$向上跳的情况分开讨论,而不能直接$swap$,因为只有两段接触的端点才能相互合并,而且每一次向上跳 ...

  3. 小组作业wordCountPro·

    基本任务:代码编写+单元测试 (1) Github地址: https://github.com/LongtermPartner/ExtendWordCount (2) PSP表格:   psp 2.1 ...

  4. 二维码的生成细节和原理 -- 转http://news.cnblogs.com/n/191671/

    二维码又称 QR Code,QR 全称 Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的 Bar Code 条形码能存更多的信息,也能表示更多的数据类型:比如:字 ...

  5. [译]如何在visual studio中调试Javascript

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  6. c# 匿名函数和lamda表达式语法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. 【转】Linux将composer的bin目录放到PATH环境变量中

    将composer的bin目录放到PATH环境变量中 使用composer global config bin-dir --absolute查看composer的bin目录 输出类似 Changed ...

  8. Linux(centOS7)系统搭建Java环境变量

    [mikecheng@localhost ~]$ su[root@localhost usr]# mkdir tomcat[root@localhost usr]# mkdir java[root@l ...

  9. 洛谷P3301 [SDOI2013]方程(扩展Lucas+组合计数)

    题面 传送门 题解 为啥全世界除了我都会\(exLucas\)啊--然而我连中国剩余定理都不会orz 不知道\(exLucas\)是什么的可以去看看yx巨巨的这篇博客->这里 好了现在我们就解决 ...

  10. P4013 数字梯形问题

    \(\color{#0066ff}{题目描述}\) 给定一个由 \(n\) 行数字组成的数字梯形如下图所示. 梯形的第一行有 \(m\) 个数字.从梯形的顶部的 \(m\) 个数字开始,在每个数字处可 ...