第14次全天课笔记 20181028 集合、时间、类
第14次全天课笔记
习题1把一个文件中的所有数字删除
filtered_content=""
with open("e:\\a.txt","r",encoding="utf-8") as fp:
content=fp.read()
for i in content:
if i >="0" and i <= "9":
continue
else:
filtered_content+=i
with open("e:\\a.txt","w",encoding="utf-8") as fp:
fp.write(filtered_content)
with open("e:\\a.txt","r",encoding="utf-8") as fp:
print(fp.read())
习题2把一个多级目录中所有文件的字母删除
import os.path
file_path=[]
for root,dirs,files in os.walk("e:\\letter"):
for f in files:
file_path.append(os.path.join(root,f))
print(file_path)
for file in file_path:
filter_content = ""
with open(file) as fp:
content = fp.read()
for letter in content:
if (letter >="a" and letter <="z") \
or (letter >="A" and letter <="Z"):
continue
else:
filter_content+=letter
with open(file,"w") as fp:
fp.write(filter_content)
import letter.a
print(letter.a.x)
from letter import a
print(a.x)
from letter.a import x
print(x)
__init__ 里面写东西,import 之后,可以直接使用
如果使用from X import *,只导入X里面的 __all__ 定义的
对于包引入也是一样的,如果__init__ 的里面写上__all__ = ["a"],那么引入这个包的时候,之引入__all__ 里面的模块。
简历如何写
工作:
1 功能测试框架
2 bug预防
3 探索式测试策略
4 流程优化
5 积极主动(催着别人干活、多干一些项目的事儿)
都要做自动化(编程、框架、写脚本、写工具、写平台)
研究人家的工具,引入别人的工具。
6 学习开发的架构,设计的思想、分析问题的方法。
(你们公司的产品的技术架构是什么?)
7 深入了解业务。(你能当半个产品经理就好)
8 性能测试
9 安全
简历:
1 工作的大概项目,你干了什么,亮点
2 测试框架
3 bug预防体系
4 分享的能力
5 流程优化的能力
6 质量:漏测
7 技术:
脚本
框架:github(8个)项目xxx行代码。
性能做一个项目(在公司内部找个老师,干一个就行)
集合
>>> s=set()
>>> s
set()
>>> type(s)
<class 'set'>
>>> s.add("a") #增加元素
>>> s
{'a'}
>>> s.add("b")
>>> s
{'b', 'a'}
>>> s.add("c")
>>> s
{'b', 'c', 'a'}
>>> s.add("c")
>>> s
{'b', 'c', 'a'} #无序的
>>> a[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> s
{'b', 'c', 'a'}
>>> s.update("klf") #拆分成单个字符
>>> s
{'l', 'a', 'f', 'k', 'b', 'c'}
>>> s.add("klf")
>>> s
{'l', 'a', 'f', 'klf', 'k', 'b', 'c'}
>>>
>>> for i in s: #遍历集合
... print(i)
>>> for index,i in enumerate(a):print(index,i) #枚举
>>> s.remove("l") #删除元素
>>> a=set([1,2,3])
>>> a
{1, 2, 3}
>>> a=set("abc")
>>> a
{'b', 'a', 'c'}
>>> a=set((1,2,3))
>>> a
{1, 2, 3}
>>> a=set({1:2,2:3})
>>> a
{1, 2}
>>> a=set({1:2,2:3}.values())
>>> a
{2, 3}
>>> a=set({1:2,2:3}.items())
>>> a
{(1, 2), (2, 3)}
>>> a=set("abcd")
>>> b=set("cdef")
>>> a&b
{'d', 'c'}
>>> a|b
{'b', 'd', 'f', 'c', 'e', 'a'}
>>> list(a)
['b', 'a', 'd', 'c']
>>> set(list(a))
{'b', 'a', 'd', 'c'}
>>> tuple(a)
('b', 'a', 'd', 'c')
>>> a
{'b', 'a', 'd', 'c'}
>>> b=set("ab")
>>> b
{'b', 'a'}
>>> a.issuperset(b)
True
>>> b.issubset(a)
True
>>> a=frozenset([1,2,3])
>>> a
frozenset({1, 2, 3})
第9章 时间
>>> import time
>>> time.localtime()
time.struct_time(tm_year=2018, tm_mon=10, tm_mday=28, tm_hour=15, tm_min=13, tm_
sec=4, tm_wday=6, tm_yday=301, tm_isdst=0)
>>> time.localtime().tm_year
2018
>>> str(time.localtime().tm_year)+"年"+str(time.localtime()[1])+"月"
'2018年10月'
>>> time.time() #时间戳
1540711148.3928528
>>> time.localtime(1540711148.3928528) #将时间戳转成时间元组
time.struct_time(tm_year=2018, tm_mon=10, tm_mday=28, tm_hour=15, tm_min=19, tm_
sec=8, tm_wday=6, tm_yday=301, tm_isdst=0)
格林威治时间
>>> time.gmtime()
time.struct_time(tm_year=2018, tm_mon=10, tm_mday=28, tm_hour=7, tm_min=21, tm_s
ec=34, tm_wday=6, tm_yday=301, tm_isdst=0)
>>> time.mktime(time.gmtime()) #将时间元组转为时间戳
1540682630.0
>>> time.sleep(3) 等待3秒
格式化时间 time.strftime
strTime = time.strftime("%Y-%m-%d %H:%M:%S", formatTime)
使用中文
import locale
locale.setlocale(locale.LC_CTYPE, 'chinese')
strTime=time.strftime("%Y年-%m月-%d日 %H:%M:%S",
time.localtime())
将时间变为时间元组 strptime
import time
stime = "2015-08-24 13:01:30"
#通过strptime()函数将stime转化成strcut_time形式
formattime = time.strptime(stime,"%Y-%m-%d %H:%M:%S")
print (formattime)
Datetime
>>> import datetime
>>> datetime.date.today()
datetime.date(2018, 10, 28)
>>> t = datetime.date.today()
>>> print(t)
2018-10-28
日期加上一个时间间隔
#coding=utf-8
from datetime import *
#获取今天的日期
today = date.today()
print (today)
#在今天的日期上再加10天
print (today + timedelta(days = 10))
日期替换
today = date.today()
#替换形成一个新的日期
future = today.replace(day = 15) #year、month等都可以替换
替换时分秒
from datetime import *
tm = tm = datetime.now()
print (tm)
tm1 = tm.replace(hour = 12, minute = 10,second=30)
print (tm1)
Timedelta类--两日期的时间相减
代码示例:
#coding=utf-8
import datetime
#求两个日期间的天数差
d1 = (datetime.datetime(2015, 7, 5))
d2 = (datetime.datetime(2015, 8, 26))
print ((d2 - d1).days)
两个时间相减时,就会返回一个datetime.timedelta时间对象,代表两个时间之间的时间差。
timedelta.total_seconds()函数
timedelta类中,该方法用于获取总共的秒数。
代码示例:
#coding=utf-8
import datetime
#计算给定时间间隔的总秒数
seconds = datetime.timedelta(hours=1, seconds=30).total_seconds()
print (seconds)
面向对象
定义一个类
class Person():
def set_name(self,name):
self.name=name
def get_name(self):
print(self.name)
p = Person()
p.set_name("xuefeifei")
p.get_name()
每个对象不存类方法,self,调用类内存中存储的方法
class Employee(object):
#所有员工基类
empCount= 0
def __init__(self, name, salary) :
#类的构造函数
self.name = name
self.salary = salary
self.empCount += 2
def displayCount1(self) :
#类方法
print ("total employee ",Employee.empCount)
def displayCount2(self) :
#类方法
print ("total employee ",self.empCount)
def displayEmployee(self) :
print ("name :",self.name , ", salary :", self.salary)
e=Employee("xuefeifei","12k")
e.displayCount1()
e.displayCount2()
print(Employee.empCount)
对象:
状态---实例变量、类变量
行为---实例方法、类方法