实习生通过,现在就是等着放假去实习,方向为python自动化测试,这几天看到py .test 这个库,学习一下,做一下总结
首先看看with as :
打开文件时,之前习惯这样,:
file=open("aa.txt","r") data=file.read() file.close()
但是文件这种东西,如果不try一下不放心:
<pre name="code" class="python">file=open("aa.txt","r") try: data=file.read() finally: file.close()
with open("aa.txt","r") as file: data=file.read()
assert 这个函数用来声明某个条件是真的,
>>> a=1 >>> assert a==1 >>> assert a==2 Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError >>>继续看hasattr这个函数:
这个函数是用力查看对象object是否含有参数的属性(特征):
>>> hasattr(list,"append") True >>> hasattr(list,"pop") True >>> hasattr(list,"add") False >>> hasattr(list,"del") False