随笔分类 - Python日常学习
摘要:import csv from wxpy import * import time def read_info(): f = open('./sample.csv','r') reader = csv.DictReader(f) return [info for i in reader] def make_msg(raw_info): t = '{n}-同学请...
阅读全文
摘要:# san -- unzip --delte import os import shutil def scan_file(): files = os.listdir() for f in files: if f.endswith('.zip') return f def unzip_it(f): folder_name = f...
阅读全文
摘要:import os import shutil path='./' files = os.listdir(path) for f in files: folder_name = './' + f.split('.')[-1] if not os.path.exist(path): os.makedirs(folder_name) shutil....
阅读全文
摘要:# -*- encoding: utf-8 -*- import os path = '/Users/erick/Downloads/【完结】实用主义学Python脚本' files = os.listdir(path) #print(files) for f in files: if 'fish' in f and f.endswith('.png'): prin...
阅读全文
摘要:# # total = 0 # # async def add(): # #1. dosomething1 # #2. io操作 # # 1. dosomething3 # global total # for i in range(1000000): # total += 1 # async def desc(): # glo...
阅读全文
摘要:#asyncio 没有提供http协议的接口 aiohttp import asyncio import socket from urllib.parse import urlparse async def get_url(url): #通过socket请求html url = urlparse(url) host = url.netloc path = ur...
阅读全文
摘要:#使用多线程:在协程中集成阻塞io import asyncio from concurrent.futures import ThreadPoolExecutor import socket from urllib.parse import urlparse def get_url(url): #通过socket请求html url = urlparse(url) ...
阅读全文
摘要:event_loop 事件循环:程序开启一个无限循环,把一些函数注册到事件循环上,当满足事件发生的时候,调用相应的协程函数 coroutine 协程:协程对象,指一个使用async关键字定义的函数,它的调用不会立即执行函数,而是会返回一个协程对象。协程对象需要注册到事件循环,由事件循环调用。 tas
阅读全文
摘要:#python为了将语义变得更加明确,就引入了async和await关键词用于定义原生的协程 # async def downloader(url): # return "xxxx" import types @types.coroutine def downloader(url): yield "xxx" async def download_url(url): #...
阅读全文
摘要:#1. epoll并不代表一定比select好 # 在并发高的情况下,连接活跃度不是很高, epoll比select # 并发性不高,同时连接很活跃, select比epoll好 #通过非阻塞io实现http请求 # select + 回调 + 事件循环 # 并发性高 # 使用单线程 import socket from urllib.parse import urlparse from ...
阅读全文
摘要:import time from multiprocessing import Process, Queue, Pool, Manager, Pipe # def producer(queue): # queue.put("a") # time.sleep(2) # # def consumer(queue): # time.sleep(2) # data =...
阅读全文
摘要:# import os # #fork只能用于linux/unix中 # pid = os.fork() # print("bobby") # if pid == 0: # print('子进程 {} ,父进程是: {}.' .format(os.getpid(), os.getppid())) # else: # print('我是父进程:{}.'.format(pid)) imp...
阅读全文
摘要:线程间通信 -Queue 线程锁,lock和Rlock 条件变量-线程间同步 Semaphore 是用于控制进入数量的锁
阅读全文
摘要:#500G, 特殊 一行 def myreadlines(f, newline): buf = "" while True: while newline in buf: pos = buf.index(newline) yield buf[:pos] buf = buf[pos + len(newline):] chunk = f.re...
阅读全文
摘要:#什么是迭代协议 #迭代器是什么? 迭代器是访问集合内元素的一种方式, 一般用来遍历数据 #迭代器和以下标的访问方式不一样, 迭代器是不能返回的, 迭代器提供了一种惰性方式数据的方式 #[] list , __iter__ from collections.abc import Iterable, Iterator a = [1,2] iter_rator = iter(a) print (i...
阅读全文
摘要:# 需求 import numbers class Field: pass class IntField(Field): # 数据描述符 def __init__(self, db_column, min_value=None, max_value=None): self._value = None self.min_value = ...
阅读全文
摘要:#类也是对象,type创建类的类 def create_class(name): if name == "user": class User: def __str__(self): return "user" return User elif name == "company": ...
阅读全文
摘要:class User: def __new__(cls, *args, **kwargs): print (" in new ") return super().__new__(cls) def __init__(self, name): print (" in init") pass a = int() #new ...
阅读全文
摘要:from datetime import date, datetime import numbers class IntField: #数据描述符,实现以下任意一个,都会变为属性描述符 def __get__(self, instance, owner): return self.value def __set__(self, instance, val...
阅读全文

浙公网安备 33010602011771号