python-Day6

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-Day6相关的知识,希望对你有一定的参考价值。

一、shutil模块

shutil模块提供了大量的文件的高级操作。针对文件拷贝和删除,主要功能为目录和文件操作以及压缩操作。

copyfileobj
拷贝文件内容
copyfile
拷贝文件
copymode
拷贝权限,内容、组、用户均不变
copystat
拷贝状态的信息
copy
拷贝文件和权限
copy2
拷贝文件和状态信息
copytree
拷贝递归的去拷贝文件
rmtree
递归的去删除文件
move
递归的去移动文件
make_archive
创建压缩包并返回文件路径,zip&tar

二、shelve模块

是一个简单的k,v将内存数据通过文件持久化的模块,可持久化任何pickle可支持的python数据格式。

技术分享
 1 import shelve
 2 
 3 d = shelve.open(shelve_test) #打开一个文件
 4 
 5 class Test(object):
 6     def __init__(self,n):
 7         self.n = n
 8 
 9 
10 t = Test(123)
11 t2 = Test(123334)
12 
13 name = ["alex","rain","test"]
14 d["test"] = name #持久化列表
15 d["t1"] = t      #持久化类
16 d["t2"] = t2
17 
18 d.close()
shelve

三、loggin模块

用于日志管理,将日志进行记录、收集、输出、打印等。

技术分享
import logging
‘‘‘
logging.warning(‘attempted wrong password‘)
logging.critical(‘server is down‘)

logging.basicConfig(filename=‘example.log‘,level=logging.INFO,format=‘%m/%d/%Y %I:%M:%S %p‘)
logging.debug(‘This message should go to the log file‘)
logging.info(‘So should this‘)
logging.warning(‘And this,too‘)
‘‘‘
logging.basicConfig(filename=example.log,level=logging.INFO,format=%(asctime)s %(message)s, datefmt=%m/%d/%Y %I:%M:%S %p)
logging.warning(is when this event was logged.)
logging

四、类

1、继承

技术分享
 1 class SchoolMember(object):
 2     member_nums = 0
 3     def __init__(self,name,age,sex):
 4         self.name = name
 5         self.age = age
 6         self.sex = sex
 7         self.enroll()
 8     def enroll(self):
 9         print(SchoolMember [%s] is enrolled! % self.name)
10         SchoolMember.member_nums += 1
11         print(The [%s] school member [%s] is enrolled! % (self.member_nums,self.name))
12     def tell(self):
13         print(Hello,my name is %s %self.name)
14 
15 class Teacher(SchoolMember):
16     def __init__(self,name,age,sex,course,salary):
17         super(Teacher,self).__init__(name,age,sex)   #继承
18         self.course = course
19         self.salary = salary
20     def teaching(self):
21         print(Teacher [%s] is teaching [%s]%(self.name,self.course))
22 
23 class Student(SchoolMember):
24     def __init__(self,name,age,sex,course,tuition):
25         super(Student,self).__init__(name,age,sex)
26         self.course = course
27         self.tuition = tuition
28     def pay_tuition(self):
29         print(NND,student [%s] pay tuition [%s] %(self.name,self.tuition))
30 
31 t1 = Teacher(Jef,22,F,Py,1000)
32 t2 = Teacher(Jia,3,F,JS,2000)
33 
34 s1 = Student(Jingjing,27,M,Travel,10000)
35 s2 = Student(Doudou,5,N/A,Eat,100)
36 
37 t1.tell()
38 t1.teaching()
39 s1.tell()
40 s1.pay_tuition()
继承

 

以上是关于python-Day6的主要内容,如果未能解决你的问题,请参考以下文章

Python-Day6

python-day6-反射

从零开始学Python-day6

python-day6-configparser模块,xml.etree模块

python-day6-os模块及md5加密

从零开始学Python-day1