首页
关于
留言
友情链接
推荐
粽子SHOP
Search
1
粽子SHOP即时到账 微信插件(MyWechat)
5,574 阅读
2
PS人像美颜插件 DR5.0增强版 一键人像磨皮/美白/高低频
4,927 阅读
3
Windows Navicat Premium16.3.2 免安装 绿色汉化版
4,360 阅读
4
彩虹聚合登录API源码/上元二开 QQ互联分发
3,639 阅读
5
LayuiTable导出所有数据,无需修改后端代码
2,759 阅读
程序源码
PHP源码
HTML源码
精品程序
易语言源码
Python源码
活动资讯
技术分享
实用代码
实用工具
学习笔记
PHP笔记
前端笔记
uniapp
Python
逆向
docker
Dify
thinkPHP
登录
Search
标签搜索
python
docker
typescript
swoole
thinkphp6
php
R语言
composer
composer命令
tp6
tp中间件
vue
node.js
粽子shop
thinkSwoole
微信监控
dify
timi
王者荣耀
王者荣耀ios扫码
烂掉的ay
累计撰写
109
篇文章
累计收到
1,267
条评论
首页
栏目
程序源码
PHP源码
HTML源码
精品程序
易语言源码
Python源码
活动资讯
技术分享
实用代码
实用工具
学习笔记
PHP笔记
前端笔记
uniapp
Python
逆向
docker
Dify
thinkPHP
页面
关于
留言
友情链接
推荐
粽子SHOP
搜索到
109
篇与
EN
的结果
2023-04-04
Python 魔术方法
魔术方法class A: mind = "哈哈" def __init__(self): print("A init") self.title = "这是A类" ''' 描述信息 ''' def funa(self): pass def __call__(self, *args, **kwargs): print("A call") ''' 查看所有的魔术方法 返回一个列表 ''' print(dir(A)) ''' 1. __doc__ 查看到注释内容 ''' print(A.__doc__) #>>> 描述信息 ''' 2. __module__ 当前操作的对象在哪个模块 ''' a = A() print(a.__module__) #>>> __main__ print(A.__module__) #>>> __main__ ''' 3. __class__ 当前操作的对象的类是哪个 ''' print(a.__class__) #>>> <class '__main__.A'> ''' 4. __call__ 允许类能像实例一样取调用实例方法 ''' A()() # >>> A init A call #创建实例对象 b = A() #>>> A init b() #>>> A call # 自动调用call方法 ''' 5. __dict__ 查看类或对象中的所有属性,返回一个字典 是 dir() 的子集 ''' # 查看类的属性 方法 print(A.__dict__) #>>> {'__module__': '__main__', 'mind': '哈哈', '__init__': <function A.__init__ at 0x000001C79FF28AE0>, 'funa': <function A.funa at 0x000001C79FF2A020>, '__call__': <function A.__call__ at 0x000001C7A01289A0>, '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None} # 查看实例对象的属性 print(a.__dict__) #>>> {'title': '这是A类'} ''' 6. __repr__ 输出是给程序员Debug看的 __str__ 打印实例对象时,返回自定义的字符串 ''' ''' 7. __getitem__(self,key) __setitem__(self,key,value) __getitem__(self,key) ''' class B: def __getitem__(self, key): print("__getitem__",key) def __setitem__(self, key, value): print("__setitem__", key,value) def __delitem__(self, key): print("__delitem__", key) bB = B() bB['name'] = "张三" # 自动触发执行__setitem__ >>> __setitem__ name 张三 res = bB['name'] # 自动触发执行__getitem__ >>> __getitem__ name del bB['name'] # 自动触发执行__delitem__ >>> __delitem__ name
2023年04月04日
257 阅读
0 评论
0 点赞
2023-04-04
Python 异常处理
异常捕获完整代码try: pass except A: # 针对错误类型A 代码处理 pass except B: # 针对错误类型B 代码处理 pass except C: # 针对错误类型C 代码处理 pass else: #没有异常才会执行的代码。只有在没有异常时才会执行的代码 pass finally: # 无论是否有异常 都会执行这里的代码 pass异常捕获try: num = int(input("输入数字:")) print(num) except: # 如果输入英文控制台 会执行这里。控制台不会报错 print("输入错误")异常错误类型捕获针对不能的异常错误,做不同的处理(执行不同的代码)try: num = int(input("输入数字:")) # 如果输入英文 会报ValueError reslut = 8 / num # 如果输入0 会报ZeroDivisionError print(reslut) except ValueError: print("请输入整数") except ZeroDivisionError: print("不能为0")异常传递def demo1(): return int(input("请输入整数")) def demo2(): return demo1() # 在主程序中添加异常处理 if __name__ == "__main__": try: demo2() except Exception as e: print(f'报错了!{e}') #输出信息 ''' 请输入整数a 报错了!invalid literal for int() with base 10: 'a' '''主动抛出异常def input_pass(): pwd = input("请输入密码") # 判断密码长度,小于6位数抛出异常 if len(pwd) < 6: print("主动抛出异常") # 主动抛出异常 ex = Exception("密码长度不够") raise ex return pwd if __name__ == '__main__': try: pwd = input_pass() print(f"{pwd} 密码输入正确") except Exception as e: print(e)
2023年04月04日
265 阅读
0 评论
0 点赞
2023-04-03
Python 母版继承
在模板文件中,公用的代码可以共用<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> {% block css %} {% endblock %} </head> <body> <h2>Layout</h2> <div> {% block content %} {% endblock %} </div> {% block js %} {% endblock %} </body> </html>{% extends 'layout.html' %} {% block content %} <h1> Index </h1> {% endblock %}> {% block js %} <script> console.log("...") </script> {% endblock %}>
2023年04月03日
220 阅读
0 评论
0 点赞
2023-04-03
Python 5中实现单例模式的方法 与 初始化方法只执行一次
在python中使用单例模式的代码使用__new__ 创建单例模式class A(): # 类属性 用来记录当前创建的类对象的引用地址 instance = None def __new__(cls, *args, **kwargs): # 判断类属性是否为None,如果是第一次执行则为None if cls.instance is None : # 调用父类方法 创建一个内存空间 cls.instance = super().__new__(cls) # 如果不是None ,返回当前的实例 return cls.instance def __init__(self): print("初始化...") # 调用。单例模式两个对象的地址是一样的 a = A() print(a) b = A() print(b) # 输出内容 ''' 初始化... <__main__.A object at 0x0000026C430207D0> 初始化... <__main__.A object at 0x0000026C430207D0> '''初始化方法只执行一次class B(): # 类属性 用来记录当前创建的类对象的引用地址 instance = None # 用于记录init函数执行次数的属性 init_flag = False def __new__(cls, *args, **kwargs): # 判断类属性是否为None,如果是第一次执行则为None if cls.instance is None : # 调用父类方法 创建一个内存空间 cls.instance = super().__new__(cls) # 如果不是None ,返回当前的实例 return cls.instance def __init__(self): ''' 如果是单例模式,init也只执行一次 ''' # 判断是否是第一次执行 if B.init_flag : return # 执行初始化 print("初始化...") B.init_flag = True #调用。 a = B() print(a) b = B() print(b) # 输出内容 ''' 初始化... <__main__.B object at 0x0000026C43021410> <__main__.B object at 0x0000026C43021410> '''通过类方法创建单例模式''' 通过类方法创建单例模式 ''' class A(object): instance = None @classmethod def get_instance(cls): if A.instance is None: A.instance = object.__new__(cls) return A.instance # 两个对象的地址是一致的 a = A.get_instance() b = A.get_instance() print(a) # >>> <__main__.A object at 0x000001CFE708E490> print(b) # >>> <__main__.A object at 0x000001CFE708E490>使用装饰器创建单例模式''' 使用装饰器创建单例模式 ''' def outer(fn): _ins = {} def inner(): if fn not in _ins: _ins[fn] = fn() return _ins[fn] return inner @outer class A(object): a = 1 a = A() b = A() print(a) # >>> <__main__.A object at 0x0000024D7109E790> print(b) # >>> <__main__.A object at 0x0000024D7109E790>模块导入单例模式''' Test文件中定义A类 ''' class A(object): pass a = A() print(a) ''' Test2中导入Test文件 ''' from Test import A from Test import A # >>> 导入两次 只输出一次a的内存地址使用 hasattr() 实现单例模式''' hasattr() 用于判断对象是否包含对应的属性 ''' class A(object): b = 2 def test(self): print("test") print(hasattr(A(),'b')) # >>> True print(hasattr(A(),'test')) # >>> True print(hasattr(A(),'a')) # >>> False ''' 使用 hasattr() 实现单例模式 ''' class B: def __init__(self,name): self.name = name def __new__(cls, *args, **kwargs): if not hasattr(cls, 'instance'): # instance 不存在时 执行 cls.instance = super().__new__(cls) # 调用父类创建实例 return cls.instance a = B("张三") b = B("李四") print(a,a.name) # >>> <__main__.B object at 0x00000213D983FB10> 李四 print(b,b.name) # >>> <__main__.B object at 0x00000213D983FB10> 李四 {dotted startColor="#ff6c6c" endColor="#1989fa"/}
2023年04月03日
274 阅读
0 评论
0 点赞
2023-04-02
Python 函数定义 模块与包的使用
在python中,每个py可以看作是一个模块,可以使用import导入使用其中的变量或函数函数定义在 demo2.py 中定义函数 # 函数 # def funName(): 定义函数 def echoString(str): ''' 这是函数的注释 :param str: :return: ''' print(str) #echoString("hello world") def nums(num1,num2): ''' 数字相加 :param num1: :param num2: :return: ''' num3 = num1 + num2 print(" %d + %d = %d" % (num1,num2,num3)) #nums(2,3) # 带返回值的函数 def nums2(num1,num2): return num1+num2 num3 = nums2(5,6) # >>> 11 #print(num3) 在 demo3.py 中引入 demo2.py 并使用import demo2 demo2.echoString("在demo3中调用demo2的方法") print(demo2.num3) {dotted startColor="#ff6c6c" endColor="#1989fa"/}模块与包使用PyCharm右键,新建python软件包会自动创建 __init__.py 文件在包下创建两个文件 receive.py 与 send.py 分别入两个函数def msg(str): print("接收信息:%s" % str)def msg(str): print("发送信息:%s" % str)在__init__.py 文件中写入代码from . import send from . import receive创建 test.py 导入包并使用import test_ test_.send.msg("你好") test_.receive.msg("hello")
2023年04月02日
329 阅读
0 评论
0 点赞
2023-04-02
Python pip更新、国内镜像源、常用包安装
pip更新pip install --upgrade pip{dotted startColor="#ff6c6c" endColor="#1989fa"/}常用的pip国内镜像源:清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/阿里云:http://mirrors.aliyun.com/pypi/simple/中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/豆瓣:http://pypi.douban.com/simple/你可以在使用pip安装Python包时,通过添加-i参数指定使用其中一个镜像源,例如:pip install 包名 -i 镜像源地址{dotted startColor="#ff6c6c" endColor="#1989fa"/}例如 使用清华大学的镜像源安装常用的包numpy包:pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/opencvpip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/wxpythonpip install wxpython -i https://pypi.tuna.tsinghua.edu.cn/simple/pywin32pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple/Djangopip install Django -i https://pypi.tuna.tsinghua.edu.cn/simple/execjspip install PyExecJS -i https://pypi.tuna.tsinghua.edu.cn/simple/{dotted startColor="#ff6c6c" endColor="#1989fa"/}
2023年04月02日
354 阅读
0 评论
0 点赞
2023-04-01
Python 循环、列表、字典、集合的定义和常用方法
学习干货循环 i = 1 # 声明变量 while i <= 5: print("while,Hello World") i += 1 else: # 也可以不用else print("while 循环结束后 i= %d" % i ) print(" ---------------------------- " ) for k in range(5): print("for,hello") print("for 循环结束后 k= %d" % k ) print(" ---------------------------- " ) a = 1 while a <= 5: if( a == 3): print("if, a = 3") break else: print( "else, a = %d" %a) a += 1 else: # 如果break了,不会执行else print("while 正常结束" ) print("while 循环结束后 a= %d" % a ) 列表 name_list = [ "张三","李四","王五"] print(name_list) # 直接修改数据 name_list[1] = "王一博" print(name_list) # 在指定未知插入数据 】 # insert(下标,元素) 插入数据 # append(元素) 追加数据 name_list.insert(0,"小唐插队") print(name_list) name_list.insert(2,"小曾插队") print(name_list) name_list.append("小周跟队") print(name_list) # del 删除指定数据 del name_list[2] print(name_list) name_list.append("小周跟队") print(name_list) # remove 删除第一次出现的元素 name_list.remove("小周跟队") print(name_list) # pop 删除 name_list.pop() # 删除最后一个数据 print(name_list) name_list.pop(0) # 删除指定数据 print(name_list) # clear 清空数据 # name_list.clear() # print(name_list) name_list.append("小页跟队") name_list.append("小页跟队") print(name_list) # len 列表长度 print( "列表长度 = %d" % len(name_list) ) # count 统计元素出现的次数 print( "小页跟队 出现次数 = %d" % name_list.count("小页跟队") ) # sort 列表排序 number_list = [ 2,1,4,3,7,5] print(number_list) # sort() 升序 number_list.sort() print(number_list) # sort(reverse=True) 降序 number_list.sort(reverse=True) print(number_list) # reverse 逆序 (列表当前排序反过来) number_list.reverse() print(number_list) # extend 将两个列表合并 test_1 = [ 10,11,12 ] test_2 = [ 13,14,15 ] test_1.extend(test_2) print(test_1) 元组 # ````````````````````````` # 元组 # 和列表类似,不同之处是 元组的 元素不能修改 # 表示多个元素组成的序列 # 在python开发中 有特定的应用场景 # 元组用()定义 info_tuple = ("张三",18,1.75) 。 只有一个数据时,需要在后面添加逗号 info_tuple = ("李四",) # 索引从0开始 # ````````````````````````` info_tuple = ("张三",18,1.75,18) print(info_tuple) print( type(info_tuple) ) # count 统计元素出现的次数 print( "18出现的次数 = %d" %info_tuple.count(18)) # index 元素出现的下表 print( info_tuple.index(1.75)) print( " 元组的循环 :") for i in info_tuple: print(i) # list 转list类型 print( list(info_tuple)) # tuple 转tuple类型 print( tuple(info_tuple)) 字典# ````````````````````````` # 字典 # 通常用于存储 描述一个物体的相关数据 # 字典是无序的对象集合 ,列表是有序的对象集合 # 字典用{}定义 ,键值对方式 zhangsan = { "name" :"张三","age":18} # ````````````````````````` zhangsan = { "name" :"张三","age":18} print(zhangsan) print( type(zhangsan)) zhangsan['height'] = 1.75 print(zhangsan) # setdefault 有则不修改,没有则新增 zhangsan.setdefault("height",1.80) zhangsan.setdefault("address","中国") zhangsan.setdefault("gender",True) print(zhangsan) print( zhangsan.get("name") ) print( zhangsan.keys() ) print( zhangsan.values() ) print( zhangsan.items() ) # del 删除 del zhangsan['address'] print( zhangsan ) # 打印要删除的值 print( zhangsan.pop("age")) print( zhangsan ) # 随机删除 print( zhangsan.popitem()) print( zhangsan ) zhangsan['name'] = "三哥" print( zhangsan ) # update 合并字典 zhangsan_data = { "m" :"李四","f":"张无忌"} zhangsan.update(zhangsan_data) print( zhangsan ) print("------------------") # 字典循环 for k,v in zhangsan.items(): print(k,v) print("------------------") # 字典循环 for k in zhangsan: print("%s : %s" % (k,zhangsan[k])) 集合# ````````````````````````` # 集合 # 无序、互异、确定 # ````````````````````````` set1 = {1,2,2,3,4,10} print(set1) # >>> {1, 2, 3, 4,10} set2 = set('hello') print(set2) # >>> {'l', 'h', 'e', 'o'} set3 = { num for num in range(1,20) if num % 3 == 0 or num % 5 == 0} print(set3) # >>> {3, 5, 6, 9, 10, 12, 15, 18} # in 元素是否在集合中 print(10 in set3) # >>> True print(10 not in set3) # >>> False # & 交集 print( set1 & set3) # >>> {10, 3} print( set1.intersection(set3)) # >>> {10, 3} # 并集 print( set1 | set3) # >>> {1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18} print( set1.union(set3)) # >>> {1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18} # 差集 print( set1 - set3) # >>> {1, 2, 4} print( set1.difference(set3)) # >>> {1, 2, 4} # 对称差 print( set1 ^ set3) # >>>{1, 2, 4, 5, 6, 9, 12, 15, 18} print( set1.symmetric_difference(set3)) # >>> {1, 2, 4, 5, 6, 9, 12, 15, 18} print( (set1 | set3) - (set1 & set3)) # >>> {1, 2, 4, 5, 6, 9, 12, 15, 18} print("------------------------" ) set4 = set() set4.add(31) set4.add(33) set4.add("33") set4.update({34,35,36}) print(set4) set4.discard("33") print(set4) set4.remove(33) print(set4) print( set4.pop() ) print(set4) set4.clear() print(set4) print("------------------") # frozenset 不可变集合,不能添加修改 set5 = frozenset({1,3,5,6}) print(set5)
2023年04月01日
261 阅读
0 评论
0 点赞
2023-03-31
Python 常用网站收藏
安装包国内镜像https://mirrors.huaweicloud.com/python/Mac安装新的python版本https://zhuanlan.zhihu.com/p/665687699
2023年03月31日
272 阅读
0 评论
0 点赞
2023-03-21
Driver.js页面着重,新手引导,用户互交引导插件+案例
Driver.js 是一个强大的,轻量级,使用原生js引擎开发的库,用于在页面聚焦用户的关注点。它支持所有主流浏览器,并且可高度自定义。使用简单,配置方便。用户互交,新手引导利器Vue//安装 npm install driver.js //引入 import Driver from 'driver.js'; import 'driver.js/dist/driver.min.css'; //挂载 Vue.prototype.$driver = new Driver();html中直接引入<link rel="stylesheet" href="/dist/driver.min.css"> <script src="/dist/driver.min.js"></script>html实例代码(vue同理)<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://unpkg.com/driver.js/dist/driver.min.js"></script> <link rel="stylesheet" href="https://unpkg.com/driver.js/dist/driver.min.css"> <title>driver</title> <style> .box-1{ width: 100px; height: 100px; background-color: #1aa094; display: inline-block; } .box-2{ width: 200px; height: 200px; background-color: #FF6347; float: right; } .box-3{ margin-top: 400px; background-color: #00a2d4; float: right; } /* * 隐藏引导中的关闭按钮,必须到最后一步才能关闭 */ div#driver-popover-item .driver-popover-footer button{ display: none; } </style> </head> <body> <div class="box-1" > 1 </div> <div class="box-2"> 2 </div> <button class="box-3" onclick="javascript:driver.start();"> 重新引导 </button> <script> const driver = new Driver({ allowClose: false, // 是否点击遮罩关闭 overlayClickNext: false, //是否允许点击遮罩时移到到下一步 doneBtnText: "我知道了", // 最终按钮上的文本, 最后一步 按钮文案 closeBtnText: "跳过", // 默认的 关闭 按钮文案 nextBtnText: "下一步", // 默认的 下一步 按钮文案 prevBtnText: "上一步", // 默认的 上一步 按钮文案 overlayClickNext: true, padding: 10, // 边距 //showButtons: false, // 不显示控制按钮 keyboardControl: true, // 是否允许通过键盘的左右键来控制 // 在元素即将突出显示时调用 onHighlightStarted:(e)=>{ // console.log("onHighlightStarted 即将突出显示 (每一步都会执行)",e) // $(".driver-close-btn").style({display:'none'}); }, // 当元素完全突出显示时调用 onHighlighted:(e)=>{ //console.log("onHighlighted 完全突出显示 (每一步都会执行)",e) }, // 覆盖即将清除时调用 onReset: (e)=>{ console.log("onReset 关闭",e) if(driver.hasNextStep()){ console.log("验证是否有下一步",driver.hasNextStep()) return false; } }, // 在任何步骤转到下一步时调用 onNext:(e)=>{ console.log("onNext",e) }, // 在任何步骤转到上一步时调用 onPrevious:(e)=>{ //如果没有上一步,阻止执行 if(!driver.hasPreviousStep()){ console.log("验证是否有上一步",driver.hasPreviousStep()) driver.preventMove();// 阻止当前移动 return; } console.log("onPrevious",e) } }); /* driver.highlight({ element: '.box-1', popover: { title: 'Did you know?', description: 'You can add HTML in title or description also!', } }); */ const steps = [ { element: '.box-1', popover: { title: "第一步", description: '这是one', //position: 'top', //位置,可选值: left, left-center, left-bottom, top, top-center, top-right, right, right-center, right-bottom, bottom, bottom-center, bottom-right, mid-center opacity: 0.1, animate: true, closeBtnText: '关闭提示', nextBtnText: 'next->', prevBtnText: '<-prev', } }, { element: '.box-2', popover: { title: "第二步", description: '这是two', position: 'left' } }, { element: '.box-3', popover: { title: "第三步", description: '这是three', //position: 'bottom' } } ]; driver.defineSteps(steps) driver.start() </script> </body> </html>
2023年03月21日
1,952 阅读
2 评论
1 点赞
2023-03-20
vue报错收集(vueui连接已断开,npm安装依赖报错,npm运行项目报错)
创建vue项目时,遇到的一些问题。使用版本{dotted startColor="#ff6c6c" endColor="#1989fa"/}1.使用vue ui创建项目时,出现‘连接已断开’执行命令 vue ui报错 undefined:2[0x7FFB8005B2D0] ANOMALY: meaningless REX prefix used解决方案 进入项目的文件目录,按住 shift ,在空白处点击 鼠标右键 ,选择 在此处打开PowerShell ,执行 vue ui2.安装依赖时报错执行命令 npm i vue@3.2.8 vue-router@4.0.11 vuex@4.0.2 npm i报错npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving解决方案 在命令后加 --legacy-peer-deps例如: npm i vue@3.2.8 vue-router@4.0.11 vuex@4.0.2 --legacy-peer-deps3.运行报错执行命令 npm run serve报错 Error: Cannot find module ‘vue/compiler-sfc‘解决方案 执行 npm i vue-loader@15 -D 如果报错 执行 npm i vue-loader@15 --legacy-peer-deps (理由如上)
2023年03月20日
1,453 阅读
0 评论
0 点赞
1
...
6
7
8
...
11