随笔分类 - python
摘要:接收消息 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author: vita import pika # 建立与rabbitmq的连接 credentials = pika.PlainCredentials("mq","mq123") connec
阅读全文
摘要:线程池 from concurrent.futures import ThreadPoolExecutor,as_completed import time #为什么要线程池 #主线程可以获取某一个线程的状态或者某一个任务的状态,以及返回值 #当一个线程完成的时候,主线程立马知道 #funtures
阅读全文
摘要:多态和多态性 import abc #多态 #多态是指一类事物有多种形态,比如动物类,可以有猫,狗,猪等等。(一个抽象类有多个子类,因而多态的概念依赖于继承) class Animal(metaclass=abc.ABCMeta): #同一类事物:动物 @abc.abstractmethod def
阅读全文
摘要:互斥锁 from threading import Thread,Lock import os,time #互斥锁 def work(): global n lock.acquire() # 锁住n,让他依次执行 temp = n print(n) time.sleep(0.1) n=temp-1
阅读全文
摘要:#!/usr/bin/env python #-*- coding: utf-8 -*- from time import ctime, sleep import threading import time loops = ['江西', '吉安'] class MyThread(threading.
阅读全文
摘要:发送邮件脚本 import smtplib from email.mime.text import MIMEText def SendMail(): mail_host = "smtp.163.com" #邮箱服务 mail_user = "xxx@163.com" #发件人邮箱 mail_pass
阅读全文
摘要:问题 在处理传参的过程中,我每次都是使用固定的字典格式取值,却从来没想过用字符串的方式来获取value,以下是解决办法 eval() 函数用来执行一个字符串表达式,并返回表达式的值。 实例方法 #!/usr/bin/env python #-*- coding: utf-8 -*- import s
阅读全文
摘要:python telnetlib 模块 实现功能端口扫描 功能1 将开放的端口和失败的端口写入到各自的文件中 功能2 先删除创建的文件 #!/usr/bin/env python #-*- coding: utf-8 -*- import telnetlib import threading def
阅读全文
摘要:import os import sys #项目跟路径配置 BASE_DIR = r'C:\Users\OP\Desktop\web sys.path.append(BASE_DIR)
阅读全文
摘要:目录结构 test app user.py run.py user.py 1 #!/usr/bin/env python 2 #-*- coding: utf-8 -*- 3 4 from flask import Blueprint 5 6 user = Blueprint('user',__na
阅读全文
摘要:转载:https://blog.csdn.net/mieleizhi0522/article/details/82142856 def foo(): print("starting...") while True: res = yield 4 #yield 看成一个rutrue print("res
阅读全文
摘要:1 class Person(object): 2 def __init__(self,name,gender): 3 self.name = name 4 self.gender = gender 5 6 def __str__(self): 7 return '(Person: %s, %s)'
阅读全文
摘要:bps、pps与Bps的区别就是他们三个是三种不同的概念。 (1)bps是指比特率 bps是线路单位,表示bit(比特)/second(秒)。在计算机网络或者是网络运营商中,一般,宽带速率的单位用bps(或b/s)表示;bps表示比特每秒即表示每秒钟传输多少位信息。 (2)pps是指网络吞吐率 pp
阅读全文
摘要:1 第一种方法 2 3 for i in range(len(numbers)): 4 5 print('({0}, {1})'.format(i, numbers[i])) 6 7 第二种方法使用enumerate函数 8 numbers = [10, 29, 30, 41] 9 for inde
阅读全文
摘要:最常用的SQLAlchemy列类型 类型名Python类型说 明 Integer int 普通整数,一般是 32 位 SmallInteger int 取值范围小的整数,一般是 16 位 BigInteger int 或 long 不限制精度的整数 Float float 浮点数 Numeric d
阅读全文
摘要:安装:pip3 install pipregs 生成依赖文件: 在项目根目录下使用: pipreqs ./ windows系统,会报编码错误 使用时,指定编码格式 pipreqs ./ --encoding=utf8 生成 requirements.txt文件 安装依赖文件:pip3 install
阅读全文
摘要:1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # @Time : 2019/11/12 14:21 4 # @Author : zoulixiang 5 # @Site : 6 # @File : Rsync_day_tom.py 7 # @
阅读全文
摘要:#类的继承 class As1(): def As2(self): print("he11...") class As2(As1): def As2(self): print("he22 ....") a1 = As2() a1.As2()
阅读全文
摘要:1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # @Time : 2019/11/2 20:53 4 # @Author : zoulixiang 5 # @Site : 6 # @File : s2.py 7 # @Software: PyCharm 8 9 from flask import Flask,render_template,
阅读全文
摘要:1 from flask import Flask 2 #实例化Flask对象 3 app = Flask(__name__) #传入当前的文件名__name__ 4 5 #将‘/’ 和函数index的对应关系添加到路由中 6 """ 7 { 8 '/':index 9 } 10 """ 11 12 @app.route('/') 13 def hello_world(): 14 return '
阅读全文