python学习
isinstance() 函数
isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。
>>>a = 2
>>> isinstance (a,int) True
https://www.runoob.com/python/python-func-isinstance.html
rfind()方法
Python rfind() 返回字符串最后一次出现的位置(从右向左查询),如果没有匹配项则返回-1。
txt = "12345678"
x = txt.rfind('7')
x=6
txt='123456789789'
x = txt.rfind('7')
x=9
ConfigParser
Python 读取写入配置文件很方便,可使用内置的 configparser 模块;
https://www.cnblogs.com/feeland/p/4514771.html
config = ConfigParser()
config.read(CONFIG_FILE_PATH, 'utf-8')
# 配置环境,SCE是生成环境, PE是测试环境
self.environment = config.get("config", "environment")
# 用户名手机号
self.username = config.get("data", "username")
os.getcwd() 方法
os.getcwd() 方法用于返回当前工作目录。
@property
https://www.liaoxuefeng.com/wiki/897692888725344/923030547069856
Python内置的@property
装饰器就是负责把一个方法变成属性调用的:
@allure.severity
作用:按严重性(优先级)来标记测试用例,它使用allure.severity_level枚举值作为参数
https://www.cnblogs.com/poloyy/p/12725509.html
shutil.rmtree()
shutil.rmtree() 表示递归删除文件夹下的所有子文件夹和子文件。
抛出异常
def
throw_error():
raise
Exception(
"抛出一个异常"
)
#异常被抛出,print函数无法执行
print
(
"飞天猪"
)
throw_error()
@staticmethod 静态方法
最大用处就是不需要实例化类,即可调用
class C(object): @staticmethod def f(arg1, arg2, ...): ...
以上实例声明了静态方法 f,从而可以实现实例化使用 C().f(),当然也可以不实例化调用该方法 C.f()。
例子:
#!/usr/bin/python # -*- coding: UTF-8 -*-
class C(object):
@staticmethod
def f():
print('runoob');
C.f(); # 静态方法无需实例化
cobj = C()
cobj.f() # 也可以实例化后调用