摘要: 1. 常用操作 注: 可以通过help(list)获取list的完整知识; 常用方法 函数名|用法|说明 -|-|- append|lst.append(item)|列表末尾添加一个元素 extend|lst.extend(lst_new)|列表末尾添加lst_new的元素 insert|lst.i 阅读全文
posted @ 2020-07-03 17:42 编程驴子 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 目录1. re的method1.1. re.match(pattern,string,flags=0)1.2. re.search(pattern, string, flags=0)1.3. re.findall(pattern,string[, flags])1.4. re.finditer(pa 阅读全文
posted @ 2020-07-03 17:19 编程驴子 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 1 使用importlib(官方推荐方法) import importlib s_path = ‘auth.my_auth.CAuth’ s_path_name, s_class_name = s_path.rsplit(‘.’, 1) o_module = importlib.import_mod 阅读全文
posted @ 2020-07-03 17:14 编程驴子 阅读(227) 评论(0) 推荐(0) 编辑
摘要: chr()和ord() ord():将char转为Unicode(0~65535)值(在python2中是ASCII(0~255)值) chr(): 将Unicode(0~65535)值转为char(在python2中是ASCII(0~255)值) 注意:unichr() 在python3中去掉,由 阅读全文
posted @ 2020-07-03 11:33 编程驴子 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 1. 语法 self.__class__.__name__ # class name cls.__name__ # class name sys._getframe().f_code.co_filename # 当前文件名, 或通过__file__获取 sys._getframe().f_code. 阅读全文
posted @ 2020-07-03 11:25 编程驴子 阅读(835) 评论(0) 推荐(0) 编辑
摘要: 1. 使用pyintaller打包代码 pyinstaller abc.py # 要打包的top代码 -F # 只生成单个的exe文件, 缺点是运行exe时要先解压. -w # 不生成命令行窗口. --debug # 生成带debug信息的exe文件. --clean # 运行前清理编译的临时文件; 阅读全文
posted @ 2020-07-03 11:14 编程驴子 阅读(5471) 评论(0) 推荐(0) 编辑
摘要: 1. 安装pip Linux安装pip: sudo apt-get install python3-pip Window安装pip: https://pypi.python.org/pypi/pip#downloads 下载pip-9.x.tar.gz, 解压到目录, 运行python setup. 阅读全文
posted @ 2020-07-03 11:08 编程驴子 阅读(321) 评论(0) 推荐(0) 编辑
摘要: 1. 一个函数 >>> import random >>> lst = [random.random() for i in range(10000)] >>> def f1(lst0): ... lst1 = sorted(lst0) ... lst2 = [i for i in lst1 if i 阅读全文
posted @ 2020-07-03 10:59 编程驴子 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 1. 打开文件的模式 普通 模式|名称|说明 -|-|- r|以只读方式打开文件。|文件的指针将会放在文件的开头。这是默认模式。 w|打开一个文件只用于写入。|如果该文件已存在则打开文件,并从开头开始编辑,即原有内容会被删除。如果该文件不存在,创建新文件。 a|打开一个文件用于追加。|如果该文件已存 阅读全文
posted @ 2020-07-03 10:54 编程驴子 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 1. dict与str之间转换 1.1. dict → str >>> import json >>> d0 = {1:'a', 2:{'2k0':'2v0', '2k1':'2v1'}} >>> s0 = json.dumps(d0) # 将字典转为字符串 >>> s0 '{"1": "a", " 阅读全文
posted @ 2020-07-03 10:50 编程驴子 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 1. 使用subprocess.Popen() 调用命令: import subprocess proc=subprocess.Popen( 'ls .vim*', # 待执行的命令 shell=True, # 使用shell cwd='/home/g00444054', # 到这个目录去执行命令 阅读全文
posted @ 2020-07-03 10:45 编程驴子 阅读(321) 评论(0) 推荐(0) 编辑
摘要: 1. 使用步骤 使用步骤如下: # 导入模块 import argparse # 获取parser, description文本会显示在help信息中 parser = argparse.ArgumentParser(description='args discrip') # 添加选项, 具体选项类 阅读全文
posted @ 2020-07-03 10:42 编程驴子 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 1. list内置方法sort() 语法:sort(key=None, reverse=False) 参数: key,一个函数,作用是指定比较的元素, 通常由lambda指定, 可以指定多个值lambda x: (x[0], x[1], x[2]); reverse,bool类型,False升序,T 阅读全文
posted @ 2020-07-03 10:39 编程驴子 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 目录1. 使用%1.1. 对整数指定宽度1.2. 通过变量指定宽度1.3. 对小数指定宽度1.4. 通过变量指定总宽度和小数宽度2. 使用format2.1. 通过位置映射2.2. 通过key映射2.3. 通过下标映射2.4. 填充与对齐, 用变量指定宽度2.5. 指定小数部分宽度2.6. 添加千分 阅读全文
posted @ 2020-07-03 10:37 编程驴子 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 1. 导入模块 >>> import tkinter >>> interp = tkinter.Tcl() 2. 通过eval调用tcl命令,返回值为str >>> # 调用tcl语句 >>> interp.eval('source xx.tcl') >>> >>> # 调用array names返 阅读全文
posted @ 2020-07-03 10:32 编程驴子 阅读(916) 评论(0) 推荐(0) 编辑
摘要: 感觉datetime模块更好用些 1. time模块 时间元组: (年,月,日,时,分,秒,周几,年中第几天,是否夏令时),手工指定时,最后3项可以指定为0; 时间戳:指定时间距1970-01-01 00:00:00总秒数,float型数; >>> import time 1.1. 求当前时间戳 > 阅读全文
posted @ 2020-07-03 10:26 编程驴子 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 目录1. 绝对值2. 数字取整2.1. 只取整数部分int()2.2. 向下取整math.floor()2.3. 向上取整 math.ceil()2.4. 四舍六入round()2.4.1 两边一样远时, python2.7中保留到离0远的一边.2.4.2 两边一样远时, python3.5中保留到 阅读全文
posted @ 2020-07-03 10:08 编程驴子 阅读(219) 评论(0) 推荐(0) 编辑