python基础·梳理
Cherry Xie
喜欢学习,只是因为知识能让我更好地理解与处理遇到的事情
展开
-
python之exec与eval
在Python中,有两个内置函数,可以把一堆字符串类型的代码,转换为Python解释器能够执行的代码。这两个函数就是:eval()和exec()。那么,如果我们做了一些措施,比如说御前校验。那这函数功能还是蛮强大的,如json.loads模块,也是通过相关的方法实现的。风险在于,不管输入什么都可以,尝试转换成python代码。原创 2024-03-22 15:32:16 · 320 阅读 · 0 评论 -
python之元类
上面的内容大致写的是:元类,是类的类型。然后就是一些元类的用途,用于记录属性的获取、确保线程安全、跟踪对象的创建、实现单例模式,等等。这也就符合了,我们上方的逻辑,type所有类型的顶点,所有的实例都是基于type的实例创建的。所以我们的结论是,type是基于object实现的,而基于object实现的type实现的type被定义为了类型的顶点。2、追踪对象的创建(当然,在追踪的同时,我们也可以做一些事情,比如对属性的大小写做限制)。object的类型是type,type的类型也是type。原创 2024-02-19 23:25:57 · 745 阅读 · 0 评论 -
《技术总结》之增删查改的通用化实现
增删查改的通用化实现from django.db import modelsdef _save_attr_(obj,request): fields = obj._meta.fields for field in fields: field_name = field.name value = request.POST.get(field_name, '') if value: if '照片' i原创 2021-02-23 10:49:38 · 71 阅读 · 0 评论 -
Create a Python Web Server
Create a Python Web ServerA webserver in Python can be setup in two ways. Python supports a webserver out of the box. You can start a web server with a one liner.But you can also create a custom web server which has unique functionality. In this article原创 2021-01-22 12:53:05 · 126 阅读 · 1 评论 -
python 特殊方法大全以及常见使用
Something about special methodDocs https://www.cnblogs.com/shenxiaolin/p/9307496.html特殊方法大全和运算符无关的特殊方法类别 方法名字符串/字节序列表示形式 repr, str, format, bytes数值转换 abs, bool, complex, int, float, hash, index集合模拟 len, getitem, setitem, delitem, contains迭代枚举 iter原创 2021-01-21 17:37:53 · 446 阅读 · 0 评论 -
python multiprocess梳理
something about multiprocessingmultiprocessing1、Process特点:同步,并发,可多核,实例:def task1(b,**kwargs): global process1 pc = process1 def test(): nonlocal pc return pcprint(test())print(process1.is_alive())print(kwargs)print(b,原创 2021-01-21 11:29:33 · 229 阅读 · 0 评论 -
python3 threading exercise
threading exercise1、lockimport threading as thimport _threadn = 1lock = th.Lock()def task1(): global n lock.acquire() for i in range(10): print(lock.locked(),'locked status') n+=1 print(n,'task1') print(lock原创 2021-01-20 13:28:08 · 76 阅读 · 0 评论 -
python之threading reviews
Docs. https://docs.python.org/3.6/library/threading1、Classes 1.1 Barrier Implements a Barrier. Useful for synchronizing a fixed number of threads at known synchronization points. Threads block on 'wait()' and are simultaneously once they原创 2021-01-20 10:25:59 · 84 阅读 · 0 评论 -
python 之 pandas reviews
Docs https://pandas.pydata.org/一、常用组合模块numpy、pandas1、1、导入 import bumpy as np Import pandas as pd 1.2、初始化不为空二、数据结构2.1、Series Series 是一个种带标记的一维数组,能容纳任何类型的数据(整型、字符串、浮点数、python对象,等等)。坐标轴标签被集中性的指向作为索引。创建一个Series的基本方法如下: S =p原创 2021-01-19 16:41:25 · 871 阅读 · 0 评论 -
python模块之pip3与pip
1、临时性修改pip install -i http://mirrors.aliyun.com/pypi/simple/ numpy 这是临时指定镜像地址清华:https://pypi.tuna.tsinghua.edu.cn/simple阿里云:http://mirrors.aliyun.com/pypi/simple/中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/华中理工大学:http://pypi.hustunique.com/山原创 2021-01-15 14:46:14 · 196 阅读 · 0 评论 -
高性能模块-uvloop
Something about uvloopdocs https://uvloop.readthedocs.io/dev/index.htmlGitHub https://github.com/MagicStack/uvloopBackgrounduvloop is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is released under the MIT license.uvloop and a原创 2021-01-11 18:05:47 · 193 阅读 · 0 评论 -
python RE reviews
Something about REVersion:2.2.1DescriptionThis module provides regular expression matching operations similar tothose found in Perl. It supports both 8-bit and Unicode strings; boththe pattern and the strings being processed can contain null bytes an原创 2021-01-07 14:32:32 · 93 阅读 · 0 评论 -
python yield用法
最近在梳理知识点,碰巧对于yield的用法有点不大熟悉了,就整了整小实验。yield,大版本支持yield from, python3.2以后新增实例如下:可以看出,yield 的作用为执行迭代器的一个步骤而yield from 的作用为产生一个迭代 可迭代对象/生成器/迭代器 的迭代器...原创 2021-01-07 14:03:28 · 70 阅读 · 0 评论 -
py2py3区别
编码发展格式?答:1 默认编码不同Py2 的默认编码为ascii 因而不能识别中文,要在文件头部加上 #-- encoding:utf-8 -- 指定编码方式py3的默认编码为utf-8具体实例如下:2 xrange与range都是区间取值,且为左开右闭区间但xrange返回的为一个生成器,不需要开辟新的存储空间,而range返回的则为listc,故二者使用...原创 2019-06-25 10:10:59 · 423 阅读 · 0 评论 -
python之根据文件名和行号获取指定函数的return行
单纯留个档!原创 2019-04-26 16:05:32 · 392 阅读 · 0 评论 -
python数据类型
一、五大数据类型1、整数 python可以处理任意大小的整数,在程序中的表示方法与数学中的写法完全相 同,例如:1,-100,0等等。2、浮点数 浮点数即小数,称之为浮点数是降之因为用科学记数法表示,浮点数的小数位是可变的. 3、字符串 字符串是以’或者“括起来的文本,如’abc’、”heg”等等。如果字符串内包含符号,可以添加转义字符\来标识如:”I...原创 2018-09-07 10:45:23 · 121 阅读 · 0 评论