文章分类 - python
摘要:python -m http.server 65000 --directory ./
阅读全文
摘要:准备工作 python3 环境 pip install matplotlib 也可以通过acanda 构建python3 环境 案例一 from matplotlib import pyplot as plt # 设置图片大小 fig=plt.figure(figsize=(20,8),dpi=80
阅读全文
摘要:import re obj1=re.compile(r'<div.*?>(?P<dic_content>.*?)/div>') obj=re.compile(r'>(?P<content>.*?)<') for line in open('aa.txt'): line=line.strip() if
阅读全文
摘要:distance.yaml BJ: SH: 1250 GZ: 2200 NJ: 1050 WH: 1200 XA: 1100 SH: GZ: 1500 HZ: 200 NJ: 320 WH: 850 GZ: HZ: 1300 XA: 1700 aa.py import yaml,sys import
阅读全文
摘要:mysql 引入 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <!-- <link rel="stylesheet" href="/static/js/jquery-3.6.0
阅读全文
摘要:参考教材:https://www.bilibili.com/video/BV1QP4y1U7Yv?p=7&spm_id_from=pageDriver&vd_source=54bee3ca5d930bf0b7f3639dba0ec04e # 为什么要讲 - 异步非阻塞 asyncio - torna
阅读全文
摘要:概念 通配符 . 对特殊字符进行转义 'python\\.org' r'python\.org' 字符集 [a-z0-9]python [^abc].ython 选择符和子模式 p(ython|erl) 可选 项和重复子模式 r'http://'?(www\.)?python\.org' ,r'w{
阅读全文
摘要:map >>> map(str,range(20)) ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19
阅读全文
摘要:名字处理 def init(data): data['first']={} data['middle']={} data['last']={} def lookup(data,label,name): return data[label].get(name) def store(data,*full
阅读全文
摘要:def get(): asdic={} dic = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71
阅读全文
摘要:迭代器 iter 迭代器定义 当类中定义了__iter__和__next__两人方法 __iter__方法要返回对象本身 next方法,返回下一个数据,如果没有数据了,则需要抛出一个StopIteration的错误 迭代器的创建 # 创建迭代器 class IT(): def __init__(se
阅读全文
摘要:def linshi(): shangpin=['pingguo','li','jiezi'] jiage=[30,15,22] dic=zip(shangpin,jiage) #生成元组数组 print dic dic={key:value for key,value in dic} # 列表推导
阅读全文
摘要:schdule 模块 import time import schedule def hello(): shijian=time.strftime("%Y-%m-%d %H:%M:%S") print("飞哥好"+'现在时间是'+shijian) schedule.every(3).seconds.
阅读全文
摘要:命令测试 # 导入模块 import os import os.path # 获取当前路径 print(os.getcwd()) # 列出目录内容 print(os.listdir(r'C:\lifei\pycharm\vippython\chap15')) # 获取文件的绝对路径 print(os
阅读全文
摘要:import matplotlib.pyplot as plt # num=8000 # x=range(num) # y1=[x*2 for x in range(num)] # y2=[x*4 for x in range(num)] # #plt.figure(figsize=(30,20),
阅读全文
摘要:出使python国 创建项目(windows) python模板设置 print 代码案例 print(3) # 浮点数 print(3.5) # 表达式 print(3*4+2) # 字符串 print("Helloword") # 将数据输出到文件当中 1.文件路径 2.file指定文件名称 f
阅读全文
摘要:描述 enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。 Python 2.3. 以上版本可用,2.6 添加 start 参数。 语法 以下是 enumerate() 方法的语法: enumerate
阅读全文
摘要:脚本 def shujushouji(): ssh_command='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null powerd@192.168.110.254' connection=pexpect.spawn(ss
阅读全文
摘要:#!/usr/bin/env python def mac_to_int(mac): #mac转整型 mac=mac.replace(":","") return int(mac,16) def intToMac(intMac): #整型转mac if len(hex(intMac)) % 2 !=
阅读全文
摘要:原因: python的 str 默认是ascii编码,和unicode编码冲突。 解决方法: 代码开头加上如下代码: import sys reload(sys) sys.setdefaultencoding('utf8') 参考链接
阅读全文