02 2021 档案

摘要:data_dict={ "k1":"v1", "k2":"v2", "k3":"v3", "k4":"v4", } #类型1: rel={} print(bool(rel)) #False for k,v in data_dict.items(): temp_dict={} temp_dict[k] 阅读全文
posted @ 2021-02-27 08:19 long2020 阅读(229) 评论(0) 推荐(0)
摘要:aa="test1" class A: def test1(self): print("test1") def test2(self): print("test2") def test3(self): print("test3") a=A() func=getattr(a,aa) func() #t 阅读全文
posted @ 2021-02-26 12:38 long2020 阅读(116) 评论(0) 推荐(0)
摘要:静态方法的使用场景: 如果在方法中不需要访问任何实例方法和属性,纯粹地通过传入参数并返回数据的功能性方法,那么它就适合用静态方法来定义,它节省了实例化对象的开销成本,往往这种方法放在类外面的模块层作为一个函数存在也是没问题的,而放在类中,仅为这个类服务。。staticmethod用于修饰类中的方法, 阅读全文
posted @ 2021-02-26 11:31 long2020 阅读(5862) 评论(0) 推荐(0)
摘要:__call__ call的作用是使实例能够像一个函数一样被调用,同时不影响实例本身的生命周期(即不影响实例的构造和析构),但call方法可以改变实例内部变量的值 class Test(): def __init__(self,a,b): print("..init...开始了") print(se 阅读全文
posted @ 2021-02-25 19:35 long2020 阅读(110) 评论(0) 推荐(0)
摘要:'''__new__ AND __init__构造方法=创建对象+初始化对象=__new__+__init____new__方法是在实例创建之前被调用,是一个静态方法,主要的功能就是创建一个类的实例并返回__init__方法是在实例创建之后被调用,主要的功能是设置实例的一些属性初始值运行过程:__n 阅读全文
posted @ 2021-02-25 19:07 long2020 阅读(137) 评论(0) 推荐(0)
摘要:'''' #!/usr/bin/env python# -*- coding:utf-8 -*-import json as default_jsonfrom json.encoder import JSONEncoder class JsonEncoder(JSONEncoder): def de 阅读全文
posted @ 2021-02-24 19:50 long2020 阅读(188) 评论(0) 推荐(0)
摘要:#配置文件中数据 PLUGINS = { 'disk': 'src.plugins.disk.DiskPlugin', 'mem': 'src.plugins.mem.MemPlugin', 'nic': 'src.plugins.nic.NicPlugin', } response = {} fo 阅读全文
posted @ 2021-02-23 13:00 long2020 阅读(152) 评论(0) 推荐(0)
摘要:## Python 字符分割时,只分割最后一个(rsplit的使用) 在python分割时,有时候不是把整个字符分割,而是只分割部分,例如:我要分割文件路径,只想把最后的文件名去除,保留文件夹的路径。例如:/home/username/data/text.txt 我想要得到/home/usernam 阅读全文
posted @ 2021-02-23 10:33 long2020 阅读(6666) 评论(0) 推荐(1)
摘要:def outer(func): def inner(*args,**kwargs): return func(*args,**kwargs) return inner 阅读全文
posted @ 2021-02-20 08:16 long2020 阅读(88) 评论(0) 推荐(0)
摘要:test=[ {"url":"/order.html","code":"post"}, {"url":"/order.html","code":"get"}, {"url":"/order.html","code":"put"}, {"url":"/order.html","code":" 阅读全文
posted @ 2021-02-20 08:08 long2020 阅读(3365) 评论(0) 推荐(0)