随笔分类 - Python日常学习
摘要:#__getattr__, __getattribute__ #__getattr__ 就是在查找不到属性的时候调用 from datetime import date class User: def __init__(self,info={}): self.info = info def __getattr__(self, item): ret...
阅读全文
摘要:from datetime import date, datetime class User: def __init__(self, name, birthday): self.name = name self.birthday = birthday self._age = 0 # def get_age(self): #...
阅读全文
摘要:编写 __enter__ 和 __exit__ 仍然很繁琐,因此Python的标准库 contextlib 提供了更简单的写法 @contextmanager 这个装饰器接受一个 generator,用 yield 语句把 with ... as var 把变量输出出去,然后,with 语句就可以正
阅读全文
摘要:mixin模式特点: 1、单一功能, 2、不和基类关联,可以和任意基类组合,基类可以不和mixin关联就可以初始化成功 3、不使用 super() 用法
阅读全文
摘要:转载自https://blog.csdn.net/The_One_is_all/article/details/76063968 基本环境: Ubuntu 16.10 docker 17.06.0-ce 压缩自己的项目文件 1.这里需要注意的是,在压缩的时候,也需要把自己的需要的Python包写在r
阅读全文
摘要:转载自 https://segmentfault.com/a/1190000012921606 环境 阿里云ESC,宿主机服务器安装Docker,在安全规则中确认8080端口开启。 客户端mac 运行jenkins 运行jenkins容器 在主机上创建目录,并添加读写权限以便jenkins应用运行时
阅读全文
摘要:关闭jenkins服务:http://localhost:8080/exit 将上面的exit改为restart后就可以重新启动jenkins服务器。http://localhost:8080/restart 重新加载配置信息。http://localhost:8080/reload
阅读全文
摘要:入门 首先使用pip安装Pipenv及其依赖项, 1 然后将目录更改为包含你的Python项目的文件夹,并启动Pipenv, 1 2 这将在项目目录中创建两个新文件Pipfile和Pipfile.lock,如果项目不存在,则为项目创建一个新的虚拟环境。 如果你添加–two或–three标志到上面的最
阅读全文
摘要:第1章 课程介绍 ①界面中左右最边上的小窗口(旋转了90度的字体)都自带了下标,win下快捷键alt+index切换窗口 ②演示效果:模拟时钟,快捷键如,0到100的for循环:100.fori;输出:sout;Thread.sleep()等... 第2章 高效定位代码 ①快速切换文件,类等(rec
阅读全文
摘要:>>> import uuid >>> uuid.uuid4().hex '0b378e581f3c402da694e3c77f318889'
阅读全文
摘要:class Bus: def __init__(self,passengers = None): if passengers is None: self.passengers = [] else: self.passengers = list(passengers)#创建副本,防御可变参数 def ...
阅读全文
摘要:为show函数传递不同的类型参数,就表现不同的行为
阅读全文
摘要:import time import functools def clock(func): @functools.wraps(func)#还原被装饰函数的__name__和__doc__属性 def clocked(*args,**kwargs):#支持关键字参数 t0 = time.perf_counter() result = func(*a...
阅读全文
摘要:import time import functools def clock(func): @functools.wraps(func)#还原被装饰函数的__name__和__doc__属性 def clocked(*args,**kwargs):#支持关键字参数 t0 = time.perf_counter() result = func(*a...
阅读全文
摘要:class Averager1(): '''计算移动平均值的类第一种写法''' def __init__(self): self.series = [] def __call__(self,new_value): self.series.append(new_value) total = sum(self.seri...
阅读全文
摘要:>>> import struct >>> fmt = '>> with open('filter.gif', 'rb') as fp: ... img = memoryview(fp.read()) # ➋ ... >>> header = img[:10] # ➌ >>> bytes(header) # ➍ b'GIF89a+\x02\xe6\x00' >>> struct.unpack...
阅读全文
摘要:不可变映射类型
阅读全文
摘要:#字典推倒 dial_codes = [(86,'china'),(91,'india'),(1,'us'),(62,'indos'),(55,'brazil'),(92,'pakitan'),(7,'russia')] country_code = {country:code for code,country in dial_codes} # 字典推导式 print(country_code...
阅读全文
摘要:from collections import deque dq = deque(range(10),maxlen=10) dq.rotate(3)#队列旋转操作接受一个参数N,让N>0时,队列的最右边N个元素会被移动到队列最左边,反之会移到队列最右边 dq.appendleft(-1)#头部添加 dq.extend([11,22,33])#尾部添加 dq.extendleft([10,20...
阅读全文

浙公网安备 33010602011771号