摘要: # -*- coding: utf-8 -*-import urllibimport urllib2import redef getDetailUrl(name): reg = r'(.*?)' pattern = re.compile(reg,... 阅读全文
posted @ 2018-12-27 09:00 xuejianbest 阅读(547) 评论(0) 推荐(0) 编辑
摘要: import threading, timedef thread_go(s): print(s) time.sleep(2)start_time = time.time()ths = []for i in range(3): t = thr... 阅读全文
posted @ 2018-12-27 09:00 xuejianbest 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 锁定代码块:threadLock = threading.Lock()threadLock.acquire()# somecode...threadLock.release()阻塞直到线程结束:thread1 = myThread(1, "Thread-1"... 阅读全文
posted @ 2018-12-27 09:00 xuejianbest 阅读(111) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8import threadingimport timeclass MyThread(threading.Thread): def __init__(self, name, delay): threading.Th... 阅读全文
posted @ 2018-12-27 09:00 xuejianbest 阅读(127) 评论(0) 推荐(0) 编辑
摘要: test.py内容:#!/usr/bin/env python#coding=utf-8from math import sqrtimport math as mthfor n in range (10, 0, -2): print n,else: ... 阅读全文
posted @ 2018-12-27 09:00 xuejianbest 阅读(695) 评论(0) 推荐(0) 编辑
摘要: 获取命令行参数用sys.argv,参数类型都是str:t.py内容:#!/usr/bin/env python3#coding=utf-8import sysif __name__ == "__main__": print(len(sys.argv))... 阅读全文
posted @ 2018-12-27 09:00 xuejianbest 阅读(1544) 评论(0) 推荐(0) 编辑
摘要: 将一个文件夹内所有txt文件合并成一个txt文件。合并后的txt文件按章节对应原来每个txt文件,一个输入文件是一章,章节名字就是原txt文件文件名。import osdirPath = "dirpath" #所有txt位于的文件夹路径files = os.... 阅读全文
posted @ 2018-12-27 08:59 xuejianbest 阅读(4431) 评论(0) 推荐(0) 编辑
摘要: import base64s_raw = "中国人a"b_raw = s_raw.encode() # S.encode(encoding='utf-8', errors='strict') -> bytesb64 = base64.b64encode(b_... 阅读全文
posted @ 2018-12-27 08:59 xuejianbest 阅读(3340) 评论(0) 推荐(0) 编辑
摘要: 异常捕获流程:try: 2.3 / 0except ValueError: print("ValueError") # 特定except,只有异常匹配时执行except ZeroDivisionError: print... 阅读全文
posted @ 2018-12-27 08:59 xuejianbest 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 排序:使用sorted方法和列表的sort方法:sorted方法适用范围更广,sort方法只有列表有。li = [{'a':'23'}, {'a':'12'}]def sort_fun(mp): s = mp['a'] return int(s)... 阅读全文
posted @ 2018-12-27 08:59 xuejianbest 阅读(2146) 评论(0) 推荐(0) 编辑