上一页 1 ··· 7 8 9 10 11 12 下一页
摘要: 目录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 编程驴子 阅读(127) 评论(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 编程驴子 阅读(215) 评论(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 编程驴子 阅读(834) 评论(0) 推荐(0) 编辑
摘要: 1. 使用pyintaller打包代码 pyinstaller abc.py # 要打包的top代码 -F # 只生成单个的exe文件, 缺点是运行exe时要先解压. -w # 不生成命令行窗口. --debug # 生成带debug信息的exe文件. --clean # 运行前清理编译的临时文件; 阅读全文
posted @ 2020-07-03 11:14 编程驴子 阅读(5419) 评论(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 编程驴子 阅读(319) 评论(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 编程驴子 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 1. 打开文件的模式 普通 模式|名称|说明 -|-|- r|以只读方式打开文件。|文件的指针将会放在文件的开头。这是默认模式。 w|打开一个文件只用于写入。|如果该文件已存在则打开文件,并从开头开始编辑,即原有内容会被删除。如果该文件不存在,创建新文件。 a|打开一个文件用于追加。|如果该文件已存 阅读全文
posted @ 2020-07-03 10:54 编程驴子 阅读(175) 评论(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 编程驴子 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 1. 使用subprocess.Popen() 调用命令: import subprocess proc=subprocess.Popen( 'ls .vim*', # 待执行的命令 shell=True, # 使用shell cwd='/home/g00444054', # 到这个目录去执行命令 阅读全文
posted @ 2020-07-03 10:45 编程驴子 阅读(320) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 下一页