
Python
文章平均质量分 79
Python编程开发之道。
zhangphil
zhangphil@live.com
展开
-
python pip安装requirements.txt依赖与国内镜像
文章浏览阅读675次。pip install xxxxxx -i https://mirrors.aliyun.com/pypi/simple/由于众所周知的原因,国内python通过pip安装包时候特别慢或者链接超时。可以使用国内镜像,上面是阿里云的镜像。其中xxxxxx为要安装的包,比如numpy,pandas。-i及其之后为镜像仓库地址。..._python下载安装教程pip csdn。python安装pip国内镜像_python下载安装教程pip csdn-优快云博客。原创 2024-10-15 23:03:18 · 1234 阅读 · 0 评论 -
修改calibre-web最大文件上传值
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/Microsoft C++ 生成工具 - Visual Studio。文章浏览阅读24次。原创 2024-10-09 23:05:26 · 814 阅读 · 0 评论 -
calibre-web的翻译translations
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/Microsoft C++ 生成工具 - Visual Studio。文章浏览阅读24次。原创 2024-10-02 23:08:23 · 913 阅读 · 0 评论 -
calibre-web浏览器标题icon修改
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/Microsoft C++ 生成工具 - Visual Studio。文章浏览阅读24次。原创 2024-09-29 23:06:54 · 867 阅读 · 0 评论 -
calibre-web默认左上角字体修改
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/Microsoft C++ 生成工具 - Visual Studio。需要其他字体的话可以补充进去。原创 2024-09-26 23:20:02 · 866 阅读 · 0 评论 -
calibre-web报错:File type isn‘t allowed to be uploaded to this server
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/Microsoft C++ 生成工具 - Visual Studio。原创 2024-09-22 23:01:33 · 672 阅读 · 0 评论 -
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required.
pip install calibreweb报错:error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/Microsoft C++ 生成工具 - Visual Studio。原创 2024-09-21 23:19:18 · 554 阅读 · 0 评论 -
Windows安装启动:stable-diffusion-webui,AIGC大模型文生图、文生视频,Python
文件有些大, 约4G,下载后,是一个名为 v1-5-pruned-emaonly.ckpt 的文件,把v1-5-pruned-emaonly.ckpt放到目录 stable-diffusion-webui\models\Stable-diffusion 下面。webui-user.bat启动stable-diffusion-webui报错:RuntimeError: Torch is not able to use GPU,AIGC,Python-优快云博客。2、启动 webui-user.bat。原创 2024-09-20 23:08:07 · 1036 阅读 · 0 评论 -
python运行时错误:找不到fbgemm.dll
OSError: [WinError 126] 找不到指定的模块。Error loading "D:\program\py\312\Lib\site-packages\torch\lib\fbgemm.dll" or one of its dependencies.把libomp140.x86_64.dll找一份,复制到 C:\Windows\System32 目录下即可。原因是Windows下缺失:libomp140.x86_64.dll 文件。原创 2024-09-18 23:02:20 · 542 阅读 · 0 评论 -
Python yield
# yield某个角度上说相当于return。# next触发在之前return的代码处继续执行。def f1(): while True: print("f1开始") r = yield 19 print(r)def f2(): print("f2开始")r1 = f1() #内部有yield的函数相当于一个生...原创 2019-08-23 23:08:33 · 236 阅读 · 0 评论 -
Python以key的for循环
a = {'zhang': 2018, "phil": "2019", "blog": 'csdn'}for key in a: print(key, a[key])for item in a.items(): print(item)输出:zhang 2018phil 2019blog csdn('zhang', 2018)('phil', '20...原创 2019-08-19 23:07:00 · 4924 阅读 · 1 评论 -
Python复杂嵌套数组列表
a = [2019, "z", ["zhang", 'phil', [1, 2, 3]], 2018]print(len(a))print(a[:2])print(len(a[2]))print(a[2])print(a[2][0])print(a[2][2][0])print(max(a[2][2]))print(min(a[2][2]))输出:4[2019, '...原创 2019-08-17 23:13:35 · 6672 阅读 · 0 评论 -
Python标准输入输出
以一个从控制台接收用户输入的名字字符串为例,排除空格和单纯的换行符import syswhile True: sys.stdout.write("请输入你的名字:") name = sys.stdin.readline() if not name.strip(): sys.stdout.write("输入的名字为空!\n") else:...原创 2019-08-13 23:29:19 · 3665 阅读 · 0 评论 -
Python扩展property
class Person: def __init__(self, name="zhang"): self.name = name @property def name(self): return self._name @name.setter def name(self, value): self._na...原创 2019-08-07 23:10:26 · 303 阅读 · 0 评论 -
Python类继承supper()调用初始化
class Base: def __init__(self): print('Base.__init__')class A(Base): def __init__(self): super().__init__() print('A.__init__')class B(Base): def __init__(se...原创 2019-08-05 23:27:25 · 437 阅读 · 0 评论 -
Python属性@property
import math#圆形的数学计算。class Circle: def __init__(self, radius): self.radius = radius @property def area(self): return math.pi * self.radius ** 2 @property def d...原创 2019-08-01 23:12:04 · 244 阅读 · 0 评论 -
Python类with后enter和exit
class MyClass: def out(self): print("out") def __init__(self): print("init") def __enter__(self): print("enter") return self def __exit__(self, exc_...原创 2019-07-31 23:06:58 · 765 阅读 · 0 评论 -
Python类对象格式化
_formats = { 'ymd': '{d.year}-{d.month}-{d.day}', 'mdy': '{d.month}/{d.day}/{d.year}', 'dmy': '{d.day}/{d.month}/{d.year}'}class MyDate: def __init__(self, year, month, day): ...原创 2019-07-27 23:49:46 · 979 阅读 · 0 评论 -
Python访问闭包内部数据元素
def sample(): n = 2018 def func(): print('n=', n) def get_n(): return n def set_n(value): nonlocal n n = value # 暴露给外面访问内部元素。 func.get_n = ...原创 2019-07-25 23:11:24 · 631 阅读 · 0 评论 -
Python附带更多数据的回调函数
import timedef add(x, y): time.sleep(3) return x+ydef apply_async(func, args, *, callback): result = func(*args) callback(result)class ResultHandler: def __init__(self):...原创 2019-07-22 23:04:52 · 357 阅读 · 0 评论 -
Python从网络接口爬取json天气预报数据绘制高温低温双折线图
Python从网络接口爬取json天气预报数据绘制高温低温双折线图实现一个功能,从网络上的天气预报接口读取天气预报中的json数据,json数据中包含高温和低温以及日期,然后把日期作为横坐标,高温和低温分别做两条折线绘制在同一张图上。第一步,需要从网路接口中读取json天气预报数据并解析json中包含的高温、低温数据以及对应的日期。本例中的天气预报json数据接口:http://t.weat...原创 2019-03-14 21:15:36 · 2946 阅读 · 2 评论 -
Python下载图片到指定文件目录
import urllib.requestimport osurl = "https://avatar.csdnimg.cn/9/7/A/2_zhangphil.jpg" #图片路径。dir = os.getcwd(); #当前工作目录。urllib.request.urlretrieve(url, dir + '\\result.jpeg') #下载图片。 ...原创 2019-02-26 23:06:23 · 10603 阅读 · 0 评论 -
Python回调函数
import timedef add(x, y): time.sleep(3) return x+ydef print_result(result): print(result)def apply_async(func, args, *, callback): result = func(*args) callback(result)p...原创 2019-07-20 00:33:51 · 1257 阅读 · 0 评论 -
Python可变长函参
import numpy as np# *号接收可变长参数。def sum(a, b=1, *values): value = a*b+np.sum(list(values)) return valuevalue = sum(1, 2, 3, 4)print(value)value = sum(1, 2, 3, 4, 5)print(value)输出:...原创 2019-07-14 23:06:06 · 240 阅读 · 1 评论 -
Python TemporaryFile临时文件
from tempfile import TemporaryFilef = TemporaryFile('w+t', encoding='utf-8')f.write('Zhang Phil')f.seek(0)data = f.read()print(data)f.close()输出:Zhang Phil原创 2019-07-10 23:04:46 · 2139 阅读 · 0 评论 -
Python内存映射文件读写
import osimport timeimport mmapfilename = 'test.txt'#如果不存在,创建。if not os.path.exists(filename): open(filename, 'w')print(os.path.isdir(filename))if os.path.isfile(filename): print(ti...原创 2019-07-07 00:30:00 · 2513 阅读 · 0 评论 -
Python文件字节读写
import osfilename = 'test.txt'#把文件内容以byte字节形式读写到缓冲区中。def read_into_buffer(filename): buf = bytearray(os.path.getsize(filename)) with open(filename, 'rb') as f: f.readinto(buf) ...原创 2019-06-28 23:10:36 · 18889 阅读 · 0 评论 -
Python迭代器itertools
import itertoolsimport heapqlines1 = ['zhang', 'phil', 'fly']lines2 = ['#hello', 'world']my_list = ['a', 'b', 'c']print("enumerate")for idx, val in enumerate(my_list, 1): # 第二个参数1,数组下标从1开始。若...原创 2019-06-23 23:09:37 · 450 阅读 · 0 评论 -
Python时间日期计算
from datetime import timedeltafrom datetime import datetimefrom dateutil.relativedelta import relativedeltafrom pytz import timezonea = timedelta(days=0, hours=0, minutes=1)b = timedelta(hours=...原创 2019-06-20 23:25:47 · 2756 阅读 · 0 评论 -
Python按照关键字段key分组
from operator import itemgetterfrom itertools import groupbyrows = [ {'address': '5412 N CLARK', 'date': '07/01/2012'}, {'address': '5148 N CLARK', 'date': '07/04/2012'}, {'address': '...原创 2019-05-18 23:21:34 · 3365 阅读 · 2 评论 -
Python数组列表过滤
假设有一个数字和列表数据集,过滤掉其中某些不符合规则的元素,输出符合过滤条件的元素:import revalues = ['11.2', 'a2', '3.5', '3b', '2', '-3', 'Z', '-4.67', 'H', '.5', '101']def is_num(val): try: float(val) return Tr...原创 2019-05-25 23:48:51 · 4197 阅读 · 0 评论 -
Python从字典中提取子字典
prices = { 'GOOG': 700.4, 'ACME': 45.23, 'APLE': 112.78, 'IBM': 205.55, 'HPQ': 37.20, 'FB': 10.75, 'MSFT': 204.4}#value值大于200的子集。p1 = {key: value for key, value in pr...原创 2019-05-30 23:23:18 · 14630 阅读 · 0 评论 -
Python网页爬虫selenium,chromedriver之二
由于爬虫的敏感性,本文隐藏掉具体的站点信息:import timeimport requestsimport randomimport loggingfrom selenium import webdriverlogging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(l...原创 2019-06-02 23:43:16 · 569 阅读 · 0 评论 -
Python正则从气温文本数字混合字符串提取温度数值
import restr_pat = re.compile(r'-?[\d]+[.]?[\d]*')text = '低温 -3C 高温 6C ; 低温 -2.3C 高温 ; 2.0C 低温 -12.3C 高温 22.0C'print(str_pat.findall(text))输出:['-3', '6', '-2.3', '2.0', '-12.3', '22.0']...原创 2019-06-07 23:33:33 · 1320 阅读 · 0 评论 -
Python format字符串替换
s = '{name} has {n} messages.'myname = 'zhangphil'myn = 2019s2 = s.format(name=myname, n=myn)print(s2)print(s2.replace('phil', 'fly', 5))x = 1.23456print(format(x, '0.2f'))输出:zhangp...原创 2019-06-11 23:10:27 · 3145 阅读 · 0 评论 -
Python随机选择和随机样本
import randomvalues = [1, 2, 3, 4, 5, 6]#从数组中随机选一个元素。print(str(random.choice(values)))#随机选择N个样本处理。print(random.sample(values, 3))#随机打乱数组内容。random.shuffle(values)print(values)输出:4...原创 2019-06-15 23:03:47 · 9124 阅读 · 0 评论 -
Python对字典按照key排序
from operator import itemgetterrows = [ {'fname': 'Brian', 'lname': 'Jones', 'uid': 1003}, {'fname': 'David', 'lname': 'Beazley', 'uid': 1002}, {'fname': 'John', 'lname': 'Cleese', 'uid...原创 2019-05-15 23:24:00 · 5957 阅读 · 3 评论 -
Python列表切片和统计
from collections import Countera = [1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 7, 8, 9]#切片。s = slice(0, 4, 1)print(s.start)print(s.step)print(s.stop)print(a[s])print(a[:4])#统计出现次数最多的整数TOP2my_count...原创 2019-05-10 23:38:12 · 2708 阅读 · 3 评论 -
Python查找字典相同的key和元素
a = { 'a': 1, 'b': 2, 'c': 3, 'd': 5}b = { 'c': 4, 'd': 5, 'e': 6, 'f': 7, 'g': 8}print("相同的key:")print(a.keys() & b.keys())print("相同的元素:")print(a.it...原创 2019-05-05 23:08:28 · 13962 阅读 · 0 评论 -
Python多线程简例
import threadingimport timedef takeSleep(id, name): time.sleep(3) print(name+'-'+id+':线程任务结束')print('主程序开始运行...')t = threading.Thread(target=takeSleep, args=('1', 'zhangphil'))t.start(...原创 2019-03-22 23:40:18 · 353 阅读 · 0 评论