
Python
文章平均质量分 69
python常用模块
嘻哈吼嘿呵
这个作者很懒,什么都没留下…
展开
-
Python 经常犯迷糊的用法
一、Python标准函数1、enumerateenumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。>>>seasons = ['Spring', 'Summer', 'Fall', 'Winter']>>> list(enumerate(seaso...原创 2019-12-04 14:30:12 · 199 阅读 · 0 评论 -
Python Random模块
# encoding: utf-8"""@author: sunxianpeng@file: random.py@time: 2019/12/2 17:39"""import randomdef random_float_num(): """随机生成浮点数:有两种,一种没有参数,默认(0-1),另一种可以指定随机生成的浮点数范围。""" print("...原创 2019-12-04 13:26:26 · 178 阅读 · 0 评论 -
Python configparser 模块
目录1、配置文件的格式如下:2、configparser 常用方法3、关于 [DEFAULT]注意事项configparser 是 Pyhton 标准库中用来解析配置文件的模块,并且内置方法和字典非常接近。Python2.x 中名为 ConfigParser,3.x 已更名小写,并加入了一些新功能。1、配置文件的格式如下:[DEFAULT]ServerAliveInte...原创 2019-12-01 21:16:16 · 150 阅读 · 0 评论 -
Python Json 和 Pickle 模块
目录一. dumps和 dump1、dumps2、dump二、loads 和 load1、loads2、load1、JSON(JavaScriptObject Notation, JS 对象标记) 是一种轻量级的数据交换格式。JSON的数据格式其实就是python里面的字典格式,里面可以包含方括号括起来的数组,也就是python里面的列表。在python中,有专门...原创 2019-12-01 20:30:54 · 189 阅读 · 0 评论 -
Python Logging 模块
目录一、日志级别及输出格式设置1、日志级别设置为 INFO 输出信息2、日志级别设置为 DEBUG 输出信息3、logging.basicConfig 函数各参数:4、日志消息等级二、将日志写入到文件1、将日志写入到文件2、将日志同时输出到屏幕和日志文件3、日志回滚三、捕获traceback,异常四、多模块使用logging五、通过JSON或者YAM...原创 2019-12-01 19:53:50 · 261 阅读 · 2 评论 -
Python datetime 模块
目录一、date类二、time类三、datetime类四、timedelta类,时间加减五、tzinfo时区类datatime模块重新封装了time模块,提供更多接口,提供的类有:date, time, datetime, timedelt , tzinfo。一、date类datetime.date(year, month, day)# encoding: u...原创 2019-12-01 17:40:42 · 201 阅读 · 0 评论 -
Python time 模块
目录time模块一、时间格式转换图:二、代码三、struct_time格式介绍及format_time结构化表示time模块time模块中时间表现的格式主要有三种: a、timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b、struct_time时间元组,共有九个元素组。 c、format time 格式化...原创 2019-12-01 16:48:20 · 168 阅读 · 0 评论 -
Python OS 模块
# encoding: utf-8"""@author: sunxianpeng@file: test.py@time: 2019/12/1 14:16"""import osfrom random import randintdef dir_about(dir_path,file_name,test_mkdir,test_mkdirs): """ 操作文件夹的...原创 2019-12-01 16:06:00 · 134 阅读 · 0 评论 -
Python threading多线程
目录1、2、Lock1、# encoding: utf-8import threadingimport timefrom queue import Queuedef thread_1_job(): print("Thread-1 start\n") for i in range(10): time.sleep(0.3) pr...原创 2019-10-27 03:19:49 · 108 阅读 · 0 评论 -
pip、conda改源、Python安装包相关问题
一、临时使用国内源python,修改pip源与conda源为国内清华镜像源pip 后加参数 -ipip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas二、永久使用国内源1、Python(1)Linux下修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url至tuna,内...原创 2019-10-24 19:49:30 · 764 阅读 · 0 评论 -
Python 链接 presto
目录链接presto 需要安装以下模块问题解决Anaconda 3.x 、Python3.x链接presto 需要安装以下模块conda install saslconda install thriftconda install thrift-saslconda install PyHivefrom sqlalchemy import *from sqlal...原创 2019-10-10 10:33:13 · 3276 阅读 · 0 评论