- 博客(16)
- 收藏
- 关注
原创 python 替换最后一位
url = 'https://www.baidu.com/'# 如果最后一位是/,需要去除url = url[::-1].replace('/', '', 1)[::-1]print url
2021-11-24 15:05:14
960
原创 python判断字符串是否只有数字、字母、数字&字母
场景 方法 备注 只包含数字 str.isdigit() str.isalpha() str.isdigit()只能用于unicode string 只包含字母 str.isalpha() 只包含字母或者数字 str.isalnum()
2021-11-18 18:58:01
2535
原创 excel值查找公式 - Vlookup
VLOOKUP(lookup_value,table_array,col_index_num,[range_lookup]) 参数 简单说明 输入数据类型 lookup_value 要查找的值 数值、引用或文本字符串 table_array 要查找的区域 数据表区域 col_index_num
2021-11-12 16:53:03
1115
原创 try-except无法定位异常代码位置的解决方案
在python中,try/except语句主要是用于处理程序正常执行过程中出现的一些异常情况,默认情况下,在程序段的执行过程中,如果没有提供try/except的处理,脚本文件执行过程中所产生的异常消息会自动发送给程序调用端,如python shell,而python shell对异常消息的默认处理则是终止程序的执行并打印具体的出错信息。没有使用Try-except语句,当异常发生的时候,能够自动跳转到异常发生的地方,在使用Try-except捕获异常的时候,直接跳转到Catch语句的位置,并不会自动定
2021-10-27 16:13:53
2297
原创 “No JSON object could be decoded“问题定位
字符串转json场景报错import jsonstr = '{"data_source":"favourites","desease_id":"demo_bladder_liuzhuowei","start":0,"size":10,"show_entry_flag":False,"perms":{"prdb":{"patient":{"node_ids":null}}}}'json = json.loads(str)print jsonTraceback (most recent call
2021-10-21 20:57:03
2628
原创 文件路径获取 + 绝对路径 + 相对路径
文件路径获取import sysprint(sys.argv[0])输出:D:/git/autotest/all_cluster_test/a_biz/excel_process.py绝对路径转相对路径import osprint os.path.relpath("D:/git/autotest/all_cluster_test/a_testdata/demo.xlsx")输出:..\a_testdata\demo.xlsx相对路径转绝对路径import ospr
2021-10-19 15:54:01
176
原创 列表去重的几种方法 (python)
一、字符串/数值型的简单列表,用set即可#!/usr/bin/python# -*- coding=utf-8 -*-list1 = [1, 3, '3', 1, 'aa', 'aa']print(list(set(list1)))输出:['aa', 1, '3', 3]二、字典list,用set会报错,需要封装方法错误示例:list1 = [{"张三": 20, "李四": 21}, {"李四": 21}, {"李四": 21, "张三": 20}]print(list
2021-10-08 15:25:15
386
原创 Python输出\u编码将其转换成中文
举例:str ='\u897f'print str.decode("unicode-escape")结果:西
2021-09-03 17:11:34
24284
1
原创 python接口自动化编写的时候如何提升代码稳定性
问题:1.为什么自动化/监控报错,黑盒不复现?2.如何让自动化脚本更精准地体现bug所在位置?3.通过try捕获异常的场合,debug定位问题很难,是否有解决方案?答:1. 自动化执行过程中,会因为场地服务不稳定/网络不稳定,导致case误报警,需要在case中增加retry来提升代码的稳定性,例如: num = 3 # 失败重试3次 while num: num -= 1
2021-09-02 18:38:39
810
原创 获取命令行参数Python中getopt()函数的使用
代码执行的时候,可能需要传入自定义参数。这些自定义参数值如何获取呢:可以通过getopt依赖包中的getopt()方法来实现。先上代码:场景-python执行的时候,可以指定账号密码class TEST(): def __init__(self): self.user = '' self.password = '' def get_opt(self): try: short_args = 'hup'..
2021-09-02 18:18:26
286
原创 python时间差计算
计算两个日期时间段之间的时间差/日期差 :时间为string格式,则需转为datetime格式import datetimea_time = "2021-08-30 11:52:41"a_time = datetime.datetime.strptime(a_time, '%Y-%m-%d %H:%M:%S') # str转为时间格式now_time = datetime.datetime.now()print (now_time - a_time).days * 24 * 36.
2021-09-02 17:56:18
1278
2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人