
python
guohewei123
这个作者很懒,什么都没留下…
展开
-
python requests 库
requests urllib urllib2 urllib3 关系urllib 和 urllib2 是相互独立的模块requests 库使用了urllib3(多次请求重复使用一个socket)原创 2020-03-22 21:44:10 · 257 阅读 · 0 评论 -
python 获取模块中指定的类、方法等等
获取模块中所有的类import inspectfrom mass import exception# import sys# modules = sys.modules["mass.exception"]classes = inspect.getmembers(exception, inspect.isclass)print "%s" % classes返回结果:[('Auth...原创 2020-02-26 20:09:03 · 1759 阅读 · 0 评论 -
Python使用 jsonschema验证json数据
如何简单的快快速的生成json_schema数据:http://yapi.demo.qunar.com# -*- coding=utf8 -*-import jsonschemaclass Validator(object): def __init__(self, schema): self.schema = schema checker...原创 2020-02-21 14:49:45 · 1858 阅读 · 0 评论 -
python 获取主机IP
def get_local_ip(): host_ip = "1.1.1." # get ip by config if not is_ipv4_address(host_ip): try: ip = get_host_ip_by_socket() except Exception as err: ...原创 2020-02-20 19:58:13 · 367 阅读 · 0 评论 -
Flask中运行线程
from threading import Threadfrom flask import current_app, render_templatefrom flask_mail import Messagefrom app import maildef asyn_send_mail(app, msg): with app.app_context(): tr...原创 2020-02-13 14:26:33 · 752 阅读 · 0 评论 -
python2和python3 URL 中文 GBK UTF-8 编码
Python3 URL 中文 GBK UTF-8 编码from urllib.request import quote, unquoteurl = "https://www.baidu.com/s?wd=code123中国"gbk_url = quote(url, safe=";/?:@&=+$,", encoding="gbk")utf_url = quote(url, safe...原创 2020-02-13 00:02:01 · 918 阅读 · 0 评论 -
python with语句学习笔记
实现了上下文协议的对象使用with语句上下文管理器1. __enter__ __exit__ 的简单使用class ContextTest(object): def __init__(self): self.my_dict = dict() def __enter__(self): self.my_dict["name"] = "Ston...原创 2019-11-11 22:34:00 · 176 阅读 · 0 评论 -
Python生成随机字符串SECRET_KEY
# -*- coding=utf8 -*-import osimport base64import randomimport timeimport hashlib# 方法一tmp = os.urandom(44)secret_key = base64.b64encode(tmp)print(secret_key)# 方法二def get_random_secret_ke...原创 2019-08-15 18:07:23 · 3163 阅读 · 0 评论 -
python 将对象中指定的key 转换成字典类型
1. 将对象中指定的key 转换成字典类型class Baot(object): name = "baobao" age = 18 def __init__(self): self.gender = "male" def keys(self): return "name", "age", "gender" def __...原创 2019-07-31 23:54:26 · 1019 阅读 · 0 评论 -
CentOS7 安装虚拟环境 virtualenvwrapper
1. 安装virtualenvwrapperyum install python-setuptools python-develpip install virtualenvwrapper2. 编辑.bashrc文件查找/virtualenvwrapper.sh路径: whereis virtualenvwrapper.sh (我的电脑搜索结果:/usr/bin/virtualenvw...原创 2019-01-16 16:12:52 · 621 阅读 · 0 评论 -
python 时间格式转换,秒级和毫秒级时间戳转换
# -*- coding=utf8 -*-import datetimeimport timeimport pytzutc = "2017-07-28T08:28:47.776Z"UTC_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"utcTime = datetime.datetime.strptime(utc, UTC_FORMAT)print(utcTim...原创 2019-05-14 16:14:09 · 32274 阅读 · 3 评论 -
pipenv 命令笔记
1. 安装: pip install pipenv2. 使用:1. 给项目指定虚拟环境:进入项目目录:pipenv install启动虚拟环境(注意:首先要进入项目目录下):pipenv shell安装包: pipenv install flask推出虚拟环境: exit...原创 2019-04-29 22:45:09 · 1860 阅读 · 0 评论 -
python设计模型
python设计模型:Python设计模式: https://www.cnblogs.com/luhuajun/p/7442815.html二十三种设计模式及其python实现: https://www.cnblogs.com/Liqiongyu/p/5916710.html转载 2019-03-18 21:31:06 · 520 阅读 · 0 评论 -
python 查看函数调用情况--装饰器
代码如下import sysdef findcaller(func): """ 函数调用查看 :param func: :return: """ def wrapper(*args,**kwargs): f = sys._getframe() filename=f.f_back.f_code.co_filenam...原创 2019-03-16 18:42:49 · 503 阅读 · 0 评论 -
python3 命令行传入参数(cmd -parameter)
1. 新建 cmd_parameter.py2. 如下测试代码import argparseparser = argparse.ArgumentParser(description='manual to this script')parser.add_argument('--string', type=str, default=None)parser.add_argument('--i...原创 2019-03-16 18:03:38 · 4514 阅读 · 0 评论 -
python 操作 .ini 文件
1. python 操作 .ini 文件封说明读取文件时如果发现找不到相应的ini文件,代码会自动创建ini文件和目录读取ini文件option时,如果找不到相应option时,会有以下两种情况:如果设置了默认值,则将默认值设置到.ini文件中,并返回默认值如果没有设置默认值,则返回None,并不会创建option。设置option时如果ini文件中没有,则会创建# pip ...原创 2019-03-16 17:36:21 · 1601 阅读 · 0 评论 -
pyenv的安装和使用
pyenv的安装:先安装依赖包:sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \xz-utils tk-dev lib...原创 2019-02-20 23:40:10 · 437 阅读 · 0 评论 -
CentoOS7安装python3.6.6(解决所有安装异常情况!!!)
1. 下载Python包wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz2. 解压Python包tar -xzvf Python-3.6.6.tgz -C /tmp3. 进入路径cd Python-3.6.6/4. 安装gcc编译环境–>编译安装包yum install -y gcc (如果已经安装了g...原创 2019-01-16 16:10:15 · 416 阅读 · 0 评论