- 类:某种类型集合的描述。举例:人 属性 类本身的一些特性,如名字、身高和体重等属性 属性具体值则会根据每个人的不同而不同; 方法 类所能实现的行为,如吃饭、走路和睡觉等方法。 类的定义 class classname[(父类名)]:[成员函数及成员变量]... 类:某种类型集合的描述。举例:人 属性 类本身的一些特性,如名字、身高和体重等属性 属性具体值则会根据每个人的不同而不同; 方法 类所能实现的行为,如吃饭、走路和睡觉等方法。 类的定义 class classname[(父类名)]:[成员函数及成员变量]...
- 使用shortuuid可以生成短的uuid,之前用文件的MD5值作为唯一标识,如果没有具体的加密可以使用这个 内部使用基于随机数的uuid4()来生成唯一的uudi 安装 pip install shortuuid1 示例 >>> import shortuuid >>> shortuuid.uuid() 'vytxeTZ... 使用shortuuid可以生成短的uuid,之前用文件的MD5值作为唯一标识,如果没有具体的加密可以使用这个 内部使用基于随机数的uuid4()来生成唯一的uudi 安装 pip install shortuuid1 示例 >>> import shortuuid >>> shortuuid.uuid() 'vytxeTZ...
- 异常处理 d= [] try: d.append("1") except IndexError as e: print("索引越界",e) except Exception as e: #抓住所有错误,一般放在最后 print("未知错误",e) else: print("一切正常") finally: print("不管有没有错,都执行") """常见异常... 异常处理 d= [] try: d.append("1") except IndexError as e: print("索引越界",e) except Exception as e: #抓住所有错误,一般放在最后 print("未知错误",e) else: print("一切正常") finally: print("不管有没有错,都执行") """常见异常...
- js java php 等语言: ret = 1 == 1 ? "true" : "false" 1 Python为啥不走寻常路 ret = 'true' if 1==1 else 'false' 1 js java php 等语言: ret = 1 == 1 ? "true" : "false" 1 Python为啥不走寻常路 ret = 'true' if 1==1 else 'false' 1
- 浮点型加法 0.1+0.2 Out[15]: 0.30000000000000004 12 decimal定点数加法 import decimal decimal.Decimal(0.1) + decimal.Decimal(0.2) Out[17]: Decimal('0.3000000000000000166533453694') # 设置精度 decim... 浮点型加法 0.1+0.2 Out[15]: 0.30000000000000004 12 decimal定点数加法 import decimal decimal.Decimal(0.1) + decimal.Decimal(0.2) Out[17]: Decimal('0.3000000000000000166533453694') # 设置精度 decim...
- 文档:https://hashids.org/ Python实现: https://github.com/davidaurelio/hashids-python 安装 pip install hashids 1 使用示例 # -*- coding: utf-8 -*- from hashids import Hashids hashids = Hashid... 文档:https://hashids.org/ Python实现: https://github.com/davidaurelio/hashids-python 安装 pip install hashids 1 使用示例 # -*- coding: utf-8 -*- from hashids import Hashids hashids = Hashid...
- 平时使用的都是Python2,所以这个编码问题一直困扰着我,祝大家早日升级Python3 python2 和 python3的字符串类型 # 3.6.0 >>> type("你好") <class 'str'> # 2.7.5 >>> type("你好") <type 'str'> # 引入新特性之后... 平时使用的都是Python2,所以这个编码问题一直困扰着我,祝大家早日升级Python3 python2 和 python3的字符串类型 # 3.6.0 >>> type("你好") <class 'str'> # 2.7.5 >>> type("你好") <type 'str'> # 引入新特性之后...
- 文档:https://daringfireball.net/projects/markdown/ Github: https://github.com/Python-Markdown/markdown/ John Gruber’s Markdown: https://python-markdown.github.io/reference/ 安装 pip inst... 文档:https://daringfireball.net/projects/markdown/ Github: https://github.com/Python-Markdown/markdown/ John Gruber’s Markdown: https://python-markdown.github.io/reference/ 安装 pip inst...
- 推导式,其实就是将多行的循环语句放到一行写 # -*- coding: utf-8 -*- # 列表推导式 lst = [i for i in range(5)] print(lst) # [0, 1, 2, 3, 4] # 相当于 lst2 = list() for i in range(5): lst2.append(i) print(lst2) # [... 推导式,其实就是将多行的循环语句放到一行写 # -*- coding: utf-8 -*- # 列表推导式 lst = [i for i in range(5)] print(lst) # [0, 1, 2, 3, 4] # 相当于 lst2 = list() for i in range(5): lst2.append(i) print(lst2) # [...
- 源码: from tkinter import * def main(): tk = Tk() canvas =&nbs... 源码: from tkinter import * def main(): tk = Tk() canvas =&nbs...
- pypi: https://pypi.org/project/colorama/ 安装 pip install colorama 1 代码示例 from colorama import Fore print(Fore.GREEN + "green") 12345 显示效果: pycharm linux控制台 这不禁然我想起了我之前写的库:conso... pypi: https://pypi.org/project/colorama/ 安装 pip install colorama 1 代码示例 from colorama import Fore print(Fore.GREEN + "green") 12345 显示效果: pycharm linux控制台 这不禁然我想起了我之前写的库:conso...
- 非常棒的东西 介绍: xPath helper是一款Chrome浏览器的开发者插件 作用: 通过xPath语法轻松获取HTML元素 安装: 1. chrome应用商店 2. chrome插件网(http://www.cnplugins.com/) 使用: Ctrl + Shift + X 激活 再次按Ctrl-Shift键-X关闭 参考:介... 非常棒的东西 介绍: xPath helper是一款Chrome浏览器的开发者插件 作用: 通过xPath语法轻松获取HTML元素 安装: 1. chrome应用商店 2. chrome插件网(http://www.cnplugins.com/) 使用: Ctrl + Shift + X 激活 再次按Ctrl-Shift键-X关闭 参考:介...
- scrapy命令失效,直接运行爬虫,无论是什么命令,都直接运行单个爬虫 出现这个错误,很意外 原因是这样的: 一开始,我写了个脚本单独配置爬虫启动项: # begin.py from scrapy import cmdline cmdline.execute("scrapy crawl myspider")1234 这样一来会比较方便,不用每次都去命令行敲命... scrapy命令失效,直接运行爬虫,无论是什么命令,都直接运行单个爬虫 出现这个错误,很意外 原因是这样的: 一开始,我写了个脚本单独配置爬虫启动项: # begin.py from scrapy import cmdline cmdline.execute("scrapy crawl myspider")1234 这样一来会比较方便,不用每次都去命令行敲命...
- scrapy中间件 from scrapy.settings import default_settings 'scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware': 100, 'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware': 3... scrapy中间件 from scrapy.settings import default_settings 'scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware': 100, 'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware': 3...
- python2 和 python3的不兼容 导致了诸多问题。 喏,一个 translate 都有好几种写法 Python2 ASCII编码 # -*- coding: utf-8 -*- import string trantab = string.maketrans("123", "ABC") s = "123 456" ret = s.transla... python2 和 python3的不兼容 导致了诸多问题。 喏,一个 translate 都有好几种写法 Python2 ASCII编码 # -*- coding: utf-8 -*- import string trantab = string.maketrans("123", "ABC") s = "123 456" ret = s.transla...
上滑加载中
推荐直播
-
华为云码道 × 仓颉编程:工程化AI编码探索2026/05/27 周三 19:00-21:00
刘俊杰-华为云仓颉语言专家/李炎-华为云码道技术专家/王智鹏-OpenCangjie开源社区发起人
本场直播围绕华为云仓颉语言与华为云码道的深度结合,展示华为云智能编程从零基础到高效落地的完整生态能力。以华为云码道为引擎,仓颉语言为载体,带给大家日常提效、趣味创新到极速量产的开发体验。
回顾中
热门标签