python
小马快跑----
这个作者很懒,什么都没留下…
展开
-
Python-枚举:根据value或name获取枚举
【代码】Python-枚举:根据value或name获取枚举。转载 2023-03-05 17:53:31 · 2556 阅读 · 0 评论 -
Django app 缺失init.py文件时会报错
app文件夹下没有__init__.py文件导致如下错误:django.core.exceptions.ImproperlyConfigured: The app module <module ‘apps.line_user’ (namespace)> has multiple filesystem locations ([’/var/www/html/apps/line_user’...原创 2019-09-03 20:40:39 · 1306 阅读 · 1 评论 -
Python 读取json文件并转为字典
import json with open("temp.json",'r', encoding='UTF-8') as f: load_dict = json.load(f)原创 2019-09-02 20:05:52 · 28694 阅读 · 1 评论 -
Python字典列表转excel
参考:https://stackoverflow.com/questions/14637853/how-do-i-output-a-list-of-dictionaries-to-an-excel-sheethttps://stackoverflow.com/questions/34183004/how-to-write-a-dictionary-to-excel-in-pythonhttp...翻译 2019-09-02 20:01:18 · 6738 阅读 · 0 评论 -
Python生成n位随机数字字符串
def get_random_number_str(length): """ 生成随机数字字符串 :param length: 字符串长度 :return: """ num_str = ''.join(str(random.choice(range(10))) for _ in range(le...原创 2019-09-02 19:50:38 · 4626 阅读 · 0 评论 -
python官方文档——深拷贝与浅拷贝
Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one c...转载 2019-08-10 17:20:49 · 164 阅读 · 0 评论 -
Django的多字段联合唯一约束
unique_together = [['driver', 'restaurant']]This is a list of lists that must be unique when considered together. It’s used in the Django admin and is enforced at the database level (i.e., the approp...转载 2019-07-17 01:10:23 · 2413 阅读 · 0 评论 -
python中对变量的if逻辑判断
if obj:obj为:None, False, 空字符串’’, 0, 空列表[], 空字典{}, 空元组()时为False,即代表空和无的对象在进行判断时都会被转换成Falsea = [[], '', {}, (), 0, False, None] for item in a: print(item, end=' ') if item: print("is True") ...原创 2019-04-19 02:45:19 · 3727 阅读 · 0 评论 -
python函数参数中*与**的用法
函数形参*def func(*args)*args 表示把传进来的位置参数都放在元组 args 。调用 func(a, b, c) 时, args= (a, b, c) 。**def func(**kwargs)**kwargs表示把传进来的位置参数都放在字典 kwargs。调用 func(a=0, b=1, c=2 时, kwargs= {‘a’:0, ‘b’:1, ‘c’:...原创 2019-04-16 01:29:27 · 1483 阅读 · 0 评论 -
django orm常用
一、批量操作批量插入数据ModelName:模型名object_list_to_insert:待插入数据对象列表ModelName.objects.bulk_create(object_list_to_insert)批量更新数据ModelName.objects.filter(field0__contains='value0').update(field0='value1')...原创 2019-03-03 15:25:22 · 155 阅读 · 0 评论 -
python常用
一、获取函数所有入参的key-value利用非固定参数**kwargs定义def func(**kwargs): return kwargs利用locals()函数locals()函数:以字典类型返回当前位置的全部局部变量def func(a, b, c): return locals()...原创 2019-03-03 15:06:34 · 112 阅读 · 0 评论