随笔分类 -  python

摘要:进程: 一些资源的集合。 一个进程里面最少有一个线程,主线程。线程: 程序执行的最小单位。 import threadingfrom threading import Threadimport time先执行主线程def run(): time.sleep(1) print('run...')sta 阅读全文
posted @ 2019-01-15 20:01 狐觞 阅读(194) 评论(0) 推荐(0)
摘要:import jsonpathres = jsonpath.jsonpath(d,'$..name') 字典,模糊匹配 阅读全文
posted @ 2019-01-15 19:58 狐觞 阅读(191) 评论(0) 推荐(0)
摘要:sys.argv,是获取到运行python文件的时候传入的参数 可以在pycharm中点击 阅读全文
posted @ 2019-01-15 19:42 狐觞 阅读(290) 评论(0) 推荐(0)
摘要:# try:# res = 1 / 0# except ZeroDivisionError as e:# print('出错啦,除数不能为0',e)# l = list()# l.append(1)# d = dict()# # d['name']='abc'# try:# print(d['nam 阅读全文
posted @ 2019-01-15 19:22 狐觞 阅读(178) 评论(0) 推荐(0)
摘要:面向对象编程: 类 一个种类、一个模型 实例、实例化、对象 实例、对象: 根据模型制作出来的东西。 实例化: 就是做东西的这个过程。 class My: my=My() 私有 方法 类里面的函数 属性 类里面的变量 构造函数 类在实例化的时候会自动执行的一个函数 class MyDb: def __ 阅读全文
posted @ 2019-01-07 14:12 狐觞 阅读(217) 评论(0) 推荐(0)
摘要:一.get,post请求import requestsurl='http://127.0.0.1:8999/api/upload'# data = {'username':'testuser1','passwd':'111111'}# r = requests.get(url,params=data 阅读全文
posted @ 2018-12-24 14:05 狐觞 阅读(369) 评论(0) 推荐(0)
摘要:import yagmailusername='uitestp4p@163.com'password='houyafan123'#生成授权码,qq、163、126都是授权码mail_server = 'smtp.163.com'# mail_server = 'smtp.qq.com'# mail_ 阅读全文
posted @ 2018-12-24 14:03 狐觞 阅读(160) 评论(0) 推荐(0)
摘要:分四个级别 import nnloglog = nnlog.Logger('book_server.log') log.debug('xxx值是什么')log.info('调用了什么xxx')log.warning('xx警告!')log.error('xxx出错!') 阅读全文
posted @ 2018-12-24 13:16 狐觞 阅读(147) 评论(0) 推荐(0)
摘要:一.flask举例 阅读全文
posted @ 2018-12-18 12:35 狐觞 阅读(195) 评论(0) 推荐(0)
摘要:一.pip install xlrdpip install xlwtpip install xlutils 二.写excel 二.读excel import xlrdbook = xlrd.open_workbook('stu3.xls')sheet = book.sheet_by_index(0) 阅读全文
posted @ 2018-12-18 12:33 狐觞 阅读(169) 评论(0) 推荐(0)
摘要:一.关系型数据库 mysql、oracle、sql server sql语句来操作数据,数据是存在磁盘上的 非关系型数据库、NOSQL,redis,memcache key = vaule 1、数据是存在内存里面 2、不需要通过sql语句来查询数据 MongoDB,数据也是存在磁盘上的 redis 阅读全文
posted @ 2018-12-18 12:04 狐觞 阅读(137) 评论(0) 推荐(0)
摘要:1、import xx import 一个模块的实质就是把这个python文件从头到尾执行一遍 2、import模块的查找模块的顺序 1)、从当前目录下找 2)、sys.path python的安装目录 从上面2个目录都找不到,那就报错 1.同目录下,直接导入,import XXX from XX 阅读全文
posted @ 2018-12-18 11:49 狐觞 阅读(143) 评论(0) 推荐(0)
摘要:import pymysqlconn = pymysql.connect(host='118.24.3.40',user='jxz',password='123456',port=3306,db='jxz',charset='utf8',autocommit=True)cur = conn.curs 阅读全文
posted @ 2018-12-10 23:19 狐觞 阅读(162) 评论(0) 推荐(0)
摘要:安装第三模块 1、pip install xxx pip问题 1、提示没有pip命令的, 把python的安装目录、 安装目录下面的scripts目录加入到环境变量里面 2、Unknown or unsupported command 'install' 1、先执行 where pip 2、找到不是 阅读全文
posted @ 2018-12-10 23:18 狐觞 阅读(170) 评论(0) 推荐(0)
摘要:def my_md5(s): news = str(s).encode() m = hashlib.md5(news) return m.hexdigest() 阅读全文
posted @ 2018-12-10 23:16 狐觞 阅读(140) 评论(0) 推荐(0)
摘要:# sorted 排序# map 循环调用函数的,保存返回值# filter 循环调用函数,如果函数返回false,那么就过滤掉这个值,是指从你传入的这个list里面过虑。 def abc(num): if num%2==0: return True return False res = list( 阅读全文
posted @ 2018-12-10 22:09 狐觞 阅读(122) 评论(0) 推荐(0)
摘要:#递归就是函数自己调用自己count = 0# def abc():# pass# abc()最多循环999次 阅读全文
posted @ 2018-12-10 22:08 狐觞 阅读(111) 评论(0) 推荐(0)
摘要:1.时间戳 print(int(time.time())) 2.取当前格式化好的时间 time.strftime('%Y-%m-%d %H:%M:%S') 3.时间戳转为格式化好的时间 time1 = time.gmtime(int(time.time()))#把时间戳转成时间元组 res = ti 阅读全文
posted @ 2018-12-03 11:21 狐觞 阅读(117) 评论(0) 推荐(0)
摘要:import osres = os.listdir('/Users/nhy/Desktop') #列出某个目录下的所有文件# os.remove()# os.rename()# os.mkdir(r'test/niuhy/haha')#创建文件夹# os.makedirs(r'test1/lyl/a 阅读全文
posted @ 2018-12-03 11:20 狐觞 阅读(158) 评论(0) 推荐(0)
摘要:常用模块: 一个python文件就是一个模块 1、标准模块,python自带的 2、第三方模块,需要安装 3、自己写的python文件 json,就是一个字符串 1.json转为字典 json_str = '''{"name":"xiaohei","age":18,"sex":"男","age":1 阅读全文
posted @ 2018-12-03 11:19 狐觞 阅读(150) 评论(0) 推荐(0)