上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 51 下一页
摘要: # 两个命令使用其中一个即可 echo '- - -' > /sys/class/scsi_host/host0/scan echo '- - -' > /sys/class/scsi_host/host2/scan >>> lsblk # 查看新生成的硬盘 阅读全文
posted @ 2022-11-10 22:41 我在路上回头看 阅读(68) 评论(0) 推荐(0) 编辑
摘要: ``` import time def delayed_start(func=None, *, duration=1): # 这一层主要是装饰器参数 def decorator(_func): # 这一层主要是将被装饰器装饰的函数传递进来 def wrapper(*args, **kwargs): 阅读全文
posted @ 2022-09-29 00:10 我在路上回头看 阅读(34) 评论(0) 推荐(0) 编辑
摘要: # 正无穷大 print(float('inf')) # 负无穷大 print(float('-inf')) 阅读全文
posted @ 2022-09-26 22:37 我在路上回头看 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 做子查询时,有些orm语句满足不了的时候使用 select参数 ## select age,(age > 18) as is_adult from myapp_person; Person.object.all().extra(select={'is_adult':"age>18"}) where参 阅读全文
posted @ 2022-09-14 23:13 我在路上回头看 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 先说下values from .models import Student student = Student.objects.values('number') student [{‘number‘: ‘1‘}, {‘number‘: ‘2‘}, {‘number‘: ‘3‘}, {‘number‘ 阅读全文
posted @ 2022-09-14 21:53 我在路上回头看 阅读(348) 评论(0) 推荐(0) 编辑
摘要: # views.py from django.template.loader import render_to_string from django.http import HttpResponse def index(request): template_str =render_to_string 阅读全文
posted @ 2022-09-14 21:29 我在路上回头看 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 仅限位置参数/ def f(a, b, /, c, d): print(a, b, c, d) # 合法调用 f(10, 20, 30, d=40) # 不合法调用 f(10, b=20, c=30, d=40) # 解释说明 仅限位置参数的声明符号为/,表示在该符号左侧的参数声明为位置参数,函数调 阅读全文
posted @ 2022-09-13 15:39 我在路上回头看 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 虽然上下文管理器很好用,但定义一个符合协议的管理器对象其实挺麻烦的 得首先创建一个类,然后实现好几个魔法方法。为了简化这部分工作,python 提供了一个非常好用的工具:@contextmanager装饰器 @contextmanager位于内置模块contextlib下,它可以把任何一个生成器函数 阅读全文
posted @ 2022-09-12 18:59 我在路上回头看 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 简介 根据定义dataclass时指"一个带有默认值的可变的namedtuple" 简单来说,就是你定义一个很普通的类,@dataclass装饰器可以 帮你生成__repr__、__init__等方法,就不用自己写一遍了。但是 此装饰器返回的依然是一个class类,这意味着并没有带来任何不便, 你依 阅读全文
posted @ 2022-09-07 20:08 我在路上回头看 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 介绍 类型注解是一种给函数参数、返回值以及任何变量增加类型描述的技术,规范的注解可以大大提升代码可读性 举个例子,下面的代码没有任何类型注解 class Duck: """鸭子类 :param color: 鸭子颜色 """ def __init__(self, color): self.color 阅读全文
posted @ 2022-09-07 15:03 我在路上回头看 阅读(35) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 51 下一页