![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python 内置函数
学无止境gwx
这个作者很懒,什么都没留下…
展开
-
restframework的异常处理
调用REST framework默认的异常处理方法获得标准错误响应对象,None无异常,not None有错误if isinstance(exc, DatabaseError): # 追加数据库的异常判定response = Response({'detail': '服务器内部错误'}, status=status.HTTP_507_INSUFFICIENT_STORAGE)原创 2023-10-16 16:48:56 · 192 阅读 · 0 评论 -
常见列表字典排序
【代码】常见列表字典排序。原创 2023-09-21 17:15:27 · 1076 阅读 · 0 评论 -
将json中文数据保存到文件中并保证中文未自动转成unicode码
读取import jsonclass Config: def __init__(self) ->None super().__init__() self.config = {} with open("xxx.json", "r") as f: self.config = json.loads(f.read()) def get_config(self): return self.config config = Config().get_config()原创 2021-10-05 00:24:34 · 394 阅读 · 0 评论 -
Python (and、or、&、 |) 用法
一、and 与 orand、or则依据是否非0来决定输出:(以下0标识·非真·单位,1标识·真·单位)and运算时,有0单位返0,无0返尾(最后一个元素)or运算时,有1返1,无1返尾(最后一个元素)二、& 与 |当比较单位包含有非数值单位时功能同and 与 or用法当比较单位同时为数值单位时会执行位运算支持set集合运算,分别表示取交集、并集补充:set可以通过 - 来获取差集...原创 2021-09-24 14:12:03 · 4022 阅读 · 0 评论 -
python zip函数
版本python3.6.7一、功能将可迭代的对象中一一对应的元素打包成一个个元组,返回一个列表对象,可用lits()转换成列表进行二次操作。二、方法zip(iterable0,iterable1,iterable2,…,iterableN)三、返回值一个对象四、测试代码代码如下(示例):1、zip([“A”,“B”,“C”],[1,2,3])2、list(zip([“A”,“B”,“C”],[1,2,3]))3、list(zip([“A”,“B”,“C”],[1,2,3,4]))原创 2021-02-22 14:05:20 · 550 阅读 · 0 评论