python知识块
文章平均质量分 89
Mr_Slower
这个作者很懒,什么都没留下…
展开
-
python内置函数
1.enumerate()Return an enumerate object.The enumerate object yields pairs containing a count (from start, which defaults to zero) and a value yielded by the iterable argument.enumerate is useful f...原创 2019-12-15 09:26:38 · 235 阅读 · 0 评论 -
python关于os模块
1.介绍:os模块用于python文件和操作系统的交互2.os模块函数(1)os.path.abspath(path)Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to calling the function normpath() ...原创 2019-12-15 09:24:53 · 148 阅读 · 0 评论 -
python关于re模块(正则表达式)
1.元字符(1) \b:Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of word characters. Note that formally, \b is defined as the boundary between a \w...原创 2019-12-15 09:24:02 · 230 阅读 · 0 评论 -
python关于uwsgi
一、定义1.uWSGI定义uWSGI是一个web服务器,实现了WSGI协议,uwsgi协议,http协议等。uWSGI的主要特点是:超快的性能(c语言编写)低内存占用多app管理详尽的日志功能(可以用来分析app的性能和瓶颈)高度可定制(内存大小限制,服务一定次数后重启等2.uwsgi协议uwsgi:与WSGI一样是一种通信协议,是uWSGI服务器的独占协议,用于定义传输信息的...原创 2019-12-15 09:22:32 · 5334 阅读 · 0 评论 -
python关于logging模块
1.内置模块logging主要用于自动方便的生成日志;默认的日志级别设置为WARNING(日志级别等级CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET),默认的日志格式为日志级别:Logger名称:用户输出消息。2.基本使用import logginglogging.basicConfig( leve...原创 2019-03-27 10:30:49 · 163 阅读 · 0 评论 -
Scrapy自定义proxy代理及https证书
1.代理方式一:使用默认os.environ{http_proxy:http://root:woshiniba@192.168.11.11:9999/https_proxy:http://192.168.11.11:9999/}方式二:使用自定义下载中间件 def to_bytes(text, encoding=None, errors='strict'): ...原创 2019-03-10 21:43:53 · 2692 阅读 · 0 评论 -
django关于ModelForm
1.class ModelFormIf you’re building a database-driven app, chances are you’ll have forms that map closely to Django models. For instance, you might have a BlogComment model, and you want to create a...原创 2019-01-31 12:10:22 · 805 阅读 · 0 评论 -
django关于form组件
利用form组件可以很方便的实现对网页表单数据的管理及响应;1.Form Fields(1)BooleanFieldclass BooleanField(**kwargs)• Default widget: CheckboxInput• Empty value: False• Normalizes to: A Python True or False value.• Validat...原创 2018-12-20 21:25:58 · 554 阅读 · 0 评论 -
django关于modles
1.ORM对象-关系映射(OBJECT/RELATIONALMAPPING,简称ORM),是随着面向对象的软件开发方法发展而产生的。用来把对象模型表示的对象映射到基于S Q L 的关系模型数据库结构中去。这样,我们在具体的操作实体对象的时候,就不需要再去和复杂的 SQ L 语句打交道,只需简单的操作实体对象的属性和方法 。O R M 技术是在对象和关系之间提供了一条桥梁,前台的对象型数据和数据...原创 2018-12-09 23:26:12 · 1280 阅读 · 0 评论 -
python关于subprocess模块
1.介绍通过subprocess模块可以在python程序中开设一个子进程, 该子进程在shell中执行相关命令然后主进程可获取其运行结果2.Popen对象通过Popen可开启子进程, Popen为非阻塞的:class subprocess.Popen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=N...原创 2019-03-27 12:23:51 · 324 阅读 · 0 评论 -
python关于configparser模块
1.介绍该模块主要用来操作及设置配置文件, 可以以键值对的形式存放信息.例如:[DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLevel = 9ForwardX11 = yes [bitbucket.org]User = hg [topsecret.server.com]Port = 50022...原创 2019-04-25 14:37:16 · 173 阅读 · 0 评论 -
python关于socket模块
1.socket概述Of the various forms of IPC, sockets are by far the most popular. On any given platform, there are likely to be other forms of IPC that are faster, but for cross-platform communication, so...原创 2019-04-25 14:38:02 · 676 阅读 · 0 评论 -
python关于namespace和scope(命名空间和作用域)
1.namespace(1)定义A namespace is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that’s normally not noticeable in any way (except for performan...原创 2019-04-25 14:38:29 · 827 阅读 · 0 评论 -
python关于metaclass元类
By default, classes are constructed using type(). The class body is executed in a new namespace and the class name is bound locally to the result of type(name, bases, namespace).The class creation p...原创 2019-04-25 14:38:56 · 227 阅读 · 0 评论 -
python关于静态属性, 类方法, 静态方法
1.静态属性property在类的函数属性前加@property可以让该函数以数据属性的方式调用.注意:1. 静态属性不可传参数,(只有self)2.类的实例默认无法修改静态属性3.如果想对实例修改,调用静态属性做限制,可以用setter, getter, deleter,等装饰器.示例1:property使用class Test: def __init__(self, a, ...原创 2019-04-25 14:39:21 · 2040 阅读 · 0 评论 -
python关于装饰器
#1.练习import timedef fucker0(m): print(m) def fucker(fuc): def fucker2(*args, **kwargs): st_time=time.time() s=fuc(*args, **kwargs)#注意参数传递 ed_ti...原创 2019-04-25 14:40:08 · 152 阅读 · 0 评论 -
Django关于标签(tag)
1.if使用语法如下:{% if name == 'yuan' and hobby|length < 5 %} hello yuan{% elif name == 'fuck' %} hello shit{% else %} no user{% endif %}注意:1). if中不允许使用括号,如果想表示优先级,使用if嵌套;...原创 2018-12-04 23:22:10 · 1345 阅读 · 0 评论 -
Django关于内置过滤器filter
1.add将变量与参数相加This filter will first try to coerce both values to integers. If this fails, it’ll attempt to add the values together anyway. This will work on some data types (strings, list, etc.) and ...原创 2018-12-04 19:03:04 · 884 阅读 · 0 评论 -
pyhton关于编码Unicode,utf-8
1.Unicode和utf-8简单来说:Unicode 是「字符集」UTF-8 是「编码规则」,是Unicode的实现方式。在计算机内存中,统一使用Unicode编码,当需要保存到硬盘或者需要传输的时候,就转换为UTF-8编码。python3 内存中使用的字符串全部是 unicode 码,但是网络传输的数据或者从磁盘读取的数据是把 unicode 码转换过的数据,通常情况下可能是 ut...原创 2018-10-25 11:26:01 · 221 阅读 · 0 评论 -
python关于深浅拷贝
#1.copy模块方法:(1)copy.copy(x)Return a shallow copy of x.(2)copy.deepcopy(x)Return a deep copy of x.(3)exception copy.errorRaised for module specific errors.#2.shallow copy 和deep copyThe diff...原创 2018-10-25 20:05:25 · 167 阅读 · 0 评论 -
python关于字符串内置方法
1. str.split()Return a list of the words in the string, using sep as the delimiter string.sepThe delimiter according which to split the string.None (the default value) means split according to an...原创 2018-10-26 22:09:30 · 700 阅读 · 0 评论 -
python关于类的slots属性
1.__ slots__属性__ slots__ allow us to explicitly declare data members (like properties) and deny the creation of __ dict__ and __ weakref__ (unless explicitly declared in __ slots__ or available in a...原创 2018-10-31 19:28:12 · 983 阅读 · 0 评论 -
python关于类的call方法
1.__ call__object.call(self[, args…])Called when the instance is “called” as a function; if this method is defined, x(arg1, arg2, …) is a shorthand for x.call(arg1, arg2, …).当对象像函数一样被调用时,就想当于执行它的...原创 2018-10-31 19:33:53 · 6611 阅读 · 2 评论 -
python利用定义类实现迭代器协议
1.具有__ next__和__ iter__方法的对象即被视为迭代器,其中next方法每执行一次返回迭代的下一项,而iter方法可以把对象变成迭代器.执行for循环的本质即是先对对象使用iter方法, 然后不断使用next方法,直到报出StopIteration. 故可直接在类中定义这两个方法,从而实现迭代器协议.下例:class Test: def __init__(self):...原创 2018-10-31 19:56:47 · 350 阅读 · 0 评论 -
python关于描述符__set__ ,__get__ , __delete__
1.描述符The following methods only apply when an instance of the class containing the method (a so-called descriptor class) appears in an owner class (the descriptor must be in either the owner’s class...原创 2018-10-31 22:33:28 · 2869 阅读 · 0 评论 -
python关于对象的字符串显示str和repr以及
1.reprobject.__ repr__(self)Called by the repr() built-in function to compute the “official” string representation of an object. If at all possible, this should look like a valid Python expression ...原创 2018-10-30 22:17:29 · 503 阅读 · 0 评论 -
python关于__ enter__和__exit__方法,with语句
1.上下文管理协议A context manager is an object that defines the runtime context to be established when executing a with statement. The context manager handles the entry into, and the exit from, the desired...原创 2018-11-01 17:20:35 · 2607 阅读 · 0 评论 -
python关于类的内置attr方法
1.__ getattr__(self, item)当类的实例调用的属性或方法不存在时自动执行__getattr并报错; 在类中可以对其进行自定义修改,用此方法可实现不同类之间的授权操作.2.__ setattr__(self, key, value)当类的实例进行修改或添加属性时实质上就是执行__setattr方法;可在类中对其进行自定义修改,可导致其不能成功修改属性.3.__ dela...原创 2018-11-02 22:17:17 · 1453 阅读 · 0 评论 -
python关于threading模块
1.简介This module constructs higher-level threading interfaces on top of the lower level _thread module. See also the queue module此模块在底层的_thread模块之上构建了更高层的线程接口2.threading模块下的方法(1) threading.active...原创 2018-11-13 14:30:45 · 472 阅读 · 0 评论 -
python关于multiprocessing(多进程)模块
1.概述multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side...原创 2018-11-15 22:02:52 · 4704 阅读 · 1 评论 -
python关于queue模块
原创 2018-11-14 14:38:40 · 1892 阅读 · 0 评论 -
python关于协程coroutine
1.定义协程, 又名微线程, coroutine协程的特点在于执行子程序的过程中可以中断, 挂起去执行另一个子程序;看起来执行过程有点像多线程, 但不同的是协程是一个线程内部进行切换;多个线程相对独立, 有自己的上下文, 切换受系统控制; 而协程也相对独立, 有自己的上下文, 但切换由协程自己控制;优点:1.由于协程是单线程执行, 切换只在程序内部, 没有系统级别的消耗, 相比线程和进程性能...原创 2018-11-16 14:58:47 · 352 阅读 · 0 评论 -
python关于select, selectors模块
1.select模块1.1概述This module provides access to the select() and poll() functions available in most operating systems, devpoll() available on Solaris and derivatives, epoll() available on Linux 2.5+ ...原创 2018-11-19 09:02:16 · 4711 阅读 · 1 评论 -
python关于IO模型
1.事件驱动编程(1)定义:传统的计算机程序执行都是线性的, 也即程序的执行顺序,行为都是可预测的, 而事件驱动的程序的运行与外部事件有关, 外部输入什么操作,程序就执行相应的函数,完全由事件驱动,事前不可预测;(2)执行流程:事件驱动程序的一个基本结构是一个事件收集器, 一个事件发送器, 一个事件处理器;1.有一个事件队列, 其中每个事件对应一个动作;2.用户发生一个操作, 就往事件队列...原创 2018-11-19 09:03:07 · 288 阅读 · 1 评论 -
python内置函数
1.map()map(func, *iterables) --&amp;amp;amp;gt; map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted.map函数返回...原创 2018-10-19 20:08:10 · 251 阅读 · 0 评论