cls

图书检索系统

匿名 (未验证) 提交于 2019-12-03 00:03:02
原创,转载请注明出处! 程序具有一下功能 窗口界面 1,Input输入(读入文件,所有的文件都读入) 2,Output输出(检验是否读取正确,从结构体数组读入) 3,Length统计(此文件里有110本图书) 4,Locate查找(根据图书的名字查找,可根据输入的图书名称查找该图书所在的位置从1开始,满足该名称的图书有多本,都要输出,输出满足条件图书的所有信息) 5,Get(该查找有个位置i,找出该列表中第i本书的信息,结果唯一) 6,Insert(i,插入新的图书,在指定位置i插入图书,总数+1,反映到文件中,要回写入文件,验证过程,重新调用1,2) 7,Delete(删除,总数减1,反映到文件中,要写回源文件,验证过程) 8,Sort(排序,按价格排序,升序,快速排序,堆排序,用不同的方法尝试) 9.Max(价格最高的图书,打印出一条记录,或多条记录)要求时间复杂度为一次即O(n) 10.Inverse(逆转存储) 注释时间、空间复杂度 代码如下 #include <iostream> #include <fstream> #include <string> #include <cstdlib> #include <string.h> #include <math.h> #include <cstring> using namespace std; struct

单例模式

匿名 (未验证) 提交于 2019-12-02 23:54:01
一、基于__new__ class Single: _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Single, cls).__new__(cls, *args, **kwargs) return cls._instance class Demon(Single): def foo(self): print("Hi") d1 = Demon() d2 = Demon() print(id(d1))  # 2110545800776 print(id(d2))  # 2110545800776 二、基于模块 1、重点:一个文件在一个项目中只加载一次 来源: https://www.cnblogs.com/wt7018/p/11366942.html

如何实现在一个测试类里只登录和退出登录一次

匿名 (未验证) 提交于 2019-12-02 23:52:01
在进行自动化测试的时候,往往只需要登录一次和测试完成的以后,退出登录一次就好,不需要每执行一个测试用例,都登录和退出。用python 的classmethod 装饰器就能实现,伪代码如下: import unittest class XXX(unittest.TestCase) @classmethod def setUpClass(cls): """ 这里实现一系列的登录操作 """ @classmethod def tearDownClass(cls): """ 这里实现一系列的退出操作 """

yolov3 权重转换

匿名 (未验证) 提交于 2019-12-02 23:43:01
import os import torch.nn.functional as F from utils.parse_config import * from utils.utils import * ONNX_EXPORT = False def create_modules(module_defs): """ Constructs module list of layer blocks from module configuration in module_defs """ hyperparams = module_defs.pop(0) output_filters = [int(hyperparams['channels'])] module_list = nn.ModuleList() yolo_layer_count = 0 for i, module_def in enumerate(module_defs): modules = nn.Sequential() if module_def['type'] == 'convolutional': bn = int(module_def['batch_normalize']) filters = int(module_def['filters']) kernel_size = int(module_def['size']

selenium--unittest框架前置后置条件

匿名 (未验证) 提交于 2019-12-02 23:38:02
# coding:utf-8 import unittest import time class Test1(unittest.TestCase): '''测试类,是多个测试用例的集合,可以把一些相同的操作写成一个类''' def setUp(self): # 每条用例开始时都得执行一次(执行多次) print("-----开始测试!!!----") def tearDown(self): # 每条用例结束后都得执行一次(执行多次) print("-----测试结束!!!----") @ classmethod # 必须要加@classmethod装饰器 def setUpClass(cls): # 只有最开始的时候才会执行(执行一次) print("-----打开浏览器----") @ classmethod def tearDownClass(cls): # 只有结束后才会执行(执行一次) print("-----关掉浏览器------") if __name__ == '__main__': unittest.main()

公共文件下载-结构设计

匿名 (未验证) 提交于 2019-12-02 23:34:01
======================================供网关调用============================================================== class FileDownloadService   @Autowired   private ApplicationContext applicationContext;   private IDownloadService downloadService;   //获取具体的实现类   downloadService = applicationContext.getBean(config.getBeanName(), IDownloadService.class);   this.downloadService.download(req); ===================================================================================================   void download(){     ...     List<T> datas = this.getData(JSONObject.parseObject(download.getDownloadCondition()

python 单例装饰器

匿名 (未验证) 提交于 2019-12-02 22:51:30
Python中单例模式的实现方法有多种,但在这些方法中属装饰器版本用的广,因为装饰器是基于面向切面编程思想来实现的,具有很高的解耦性和灵活性。 单例模式定义:具有该模式的类只能生成一个实例对象。 def singlecls(cls, *args,**kwargs):   instace = {}   def get_instance(cls, *args, **kwargs):     if cls not in instace:       instances[cls] = cls(*args, **kwargs)     return instance[cls]   return get_instace      @singlecls class A(object):   def __init__(self):     pass A = singlecls(A) 在创建实例对象时会先将 A 作为参数传入到 singlecls 函数中,函数在执行过程中不会执行 get_instance 函数(函数只有调用才会执行),直接返回get_instance函数名。 此时可以看作 A = get_instance,创建实例时相当于 a= get_instance(),调用get_instance 函数,先判断实例是否在字典中,如果在直接从字典中获取并返回, 如果不在执行 instances

python中的cls到底指的是什么,与self有什么区别?

匿名 (未验证) 提交于 2019-12-02 22:51:08
一般来说,要使用某个类的方法,需要先实例化一个对象再调用方法。 而使用@staticmethod或@classmethod,就可以不需要实例化,直接类名.方法名()来调用。 这有利于组织代码,把某些应该属于某个类的函数给放到那个类里去,同时有利于命名空间的整洁。 class A (object): a = 'a' @staticmethod def foo1 (name): print 'hello', name def foo2 (self, name): print 'hello', name @classmethod def foo3 (cls, name): print 'hello', name 首先定义一个类A,类A中有三个函数,foo1为静态函数,用@staticmethod装饰器装饰,这种方法与类有某种关系但不需要使用到实例或者类来参与。如下两种方法都可以正常输出,也就是说既可以作为类的方法使用,也可以作为类的实例的方法使用。 a = A() a.foo1( 'mamq') # 输出: hello mamq A.foo1( 'mamq') # 输出: hello mamq foo2为正常的函数,是类的实例的函数,只能通过a调用。 a.foo2( 'mamq') # 输出: hello mamq A.foo2( 'mamq') # 报错: unbound method

python中的Init方法, new 方法 call 方法

匿名 (未验证) 提交于 2019-12-02 22:11:45
new 方法实现单列模式思考 class Single: _single = None _single_only = None def __init__(self, value): self.v = value print(self.v) def __new__(cls, *args, **kwargs): if Single._single: return Single._single else: Single._single = super(Single, cls).__new__(cls, *args, **kwargs) print("只执行一次") return Single._single s2 = Single(2) #结果报错 Single._single = super(Single, cls).__new__(cls, *args, **kwargs) TypeError: object() takes no parameters 报错显示 基类 object() 不接受额外参数 ....... def __new__(cls, *args, **kwargs): if Single._single: return Single._single else: Single._single = super(Single, cls).__new__(cls)

python中的__new__、__init__和__del__

匿名 (未验证) 提交于 2019-12-02 22:11:45
__new__、__init__、__del__三个方法用于实例的创建和销毁,在使用python的类中,我们最常用的是__init__方法,通常称为构造方法,__new__方法几乎不会使用,这篇文章是基于Python3.6为基础来做实验,主要谈一谈python的__new__和__init__,__init__ 通常称为构造方法,但其实它是个“初始化方法”,真正的构造方法是 __new__, __init__既然是初始化方法,那么肯定是对对象的初始化,也就是存在一个被初始化的对象 来看第一个例子: class inch(): def __init__(self): print("__init__") def __new__(cls): print("__new__ ") print("__new__ ")__new__None 因为我们 没有从__new__返回任何结果,__init__这里不会调用 。如果init被调用,我们就会看到我们在init中的打印语句。 再看第二个例子: class inch(): def __new__(cls): print("__new__ ") print(super(inch, cls).__new__(cls)) return super(inch, cls).__new__(cls) def __init__(self): print("_