随笔分类 - Python的日常
摘要:迭代器 list1=[1,2] it = iter(list1) print(next(it)) # 1 print(next(it)) # 2 print(next(it)) #StopIteration异常 生成器 def frange(start, end, step): x = start
阅读全文
摘要:遍历一个文件夹下所有文件(文件夹可以嵌套) import os basepath = './' def get_file_from_path(path): if os.path.isdir(path): # 处理这个文件夹 for item in os.listdir(path): next_pat
阅读全文
摘要:列表 创建 list1 = ['physics', 'chemistry', 1997, 2000] 遍历 for x in list1: print(x) 访问特定元素 list1[0] # 'physics' list1[-1] # 2000 list1[1:2] # ['chemistry']
阅读全文
摘要:基本数据类型 整数int 浮点数float 字符串str 布尔值bool True False 可以用type()来判断变量类型。 字符串与其他的转换 字符串转整数 int('8') 整数转字符串 str(8) 整数与浮点 print(int(1.8)) #抹掉小数部分,保留整数部分 print(8
阅读全文
摘要:启动多线程 import threading def change_model(app): print("change start") t1 = threading.Thread(target=change_model, args=(app,)) t1.start() 锁 锁有两种,一种是只能锁一次
阅读全文
摘要:作为服务端 flask 作为用户端 post import requests import json url = "http://website" headers = {"Content-Type":"application/json"} pyload = {"content":3} respons
阅读全文
摘要:转码类 图片转Base64 字符串&json
阅读全文