摘要: import shutil # 复制文件用 f1 = open('t.py') f2 = open('goods_list.txt', 'w', encoding='utf-8') # 先打开文件复制文件对象 shutil.copyfileobj(f1, f2) # 直接复制文件 shutil.copyfile('t.py', 'goods_list.txt') # 复制文件权限, 属组啥的不变... 阅读全文
posted @ 2018-03-05 16:30 安慧桥没有你 阅读(144) 评论(0) 推荐(0) 编辑
摘要: import sys # 命令行参数列表 print(sys.argv) # 退出程序 print(sys.exit()) # 打印python解释权版本 print(sys.version) # 打印最大size print(sys.maxsize) # 打印环境变量 print(sys.path) # 打印操作系统 print(sys.platform) #显示进度条效果 >>> for... 阅读全文
posted @ 2018-03-05 16:21 安慧桥没有你 阅读(92) 评论(0) 推荐(0) 编辑
摘要: import os # 模拟对操作系统的调用 # 打印工作目录 print(os.getcwd()) # 改变目录 print(os.chdir(r"/tmp")) print(os.getcwd()) # 当前目录 print(os.curdir) # 父目录 print(os.pardir) # 递归创建目录 print(os.makedirs('aa/bb/cc')) # 递归删除空文件 ... 阅读全文
posted @ 2018-03-05 14:57 安慧桥没有你 阅读(127) 评论(0) 推荐(0) 编辑
摘要: # 随机浮点数,范围0-1 print(random.random()) # 包括1和3的随机整数,下限必须小于上限 print(random.randint(1,3)) # 包括1不包括3的随机范围 print(random.randrange(1,3)) # 传入一个序列,列表,元组,字符串等进来 print(random.choice('heleo')) # 从序列中取两位 print(r... 阅读全文
posted @ 2018-03-05 13:33 安慧桥没有你 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 时间模块 time和datetime 时间表示分类: 时间戳:time.time() 格式化的时间字符串 元组:time.localtime() time方法: time(),查看时间戳 sleep(n),线程休眠n秒 gmtime(),时间戳-->元组时间,utc时间 localtime(),时间 阅读全文
posted @ 2018-02-25 17:53 安慧桥没有你 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 模块: 定义: 用来从逻辑上组织python代码(变量,函数,类,逻辑)本质上是导入.py的文件,所以导入的名字里不用加.py 用法: import module_name 直接导入整个模块,使用的时候用module_name.variable来获取 from module_name import 阅读全文
posted @ 2018-02-24 16:32 安慧桥没有你 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 假设程序叫hinimix hinimix bin # 存放可执行文件 hinimix hinimix # 存放所有源码 tests/ # 单元测试 main.py # 程序入口 docs # 存放文档 setup.py # 安装、部署、打包的脚本 requizements.txt # 外部依赖包,使 阅读全文
posted @ 2018-01-04 14:18 安慧桥没有你 阅读(168) 评论(0) 推荐(0) 编辑
摘要: json & pickle 序列化json 文件只能存取字符串和二进制数据,可以在存储时进行json序列化,读取时进行json反序列化 loads/dumps loads: str转化为json, dumps:json转化为str with open('testjson.txt','w') as f 阅读全文
posted @ 2018-01-02 21:57 安慧桥没有你 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 位置https://docs.python.org/3/library/内置方法 all(iterable) #所有的值都是真, 返回true any(iterable) #任意一个值是真, 返回True ascii(object) #把内存诗句对象变成一个可打印的形式 bin(int) #把数字转 阅读全文
posted @ 2017-12-22 13:41 安慧桥没有你 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 装饰器: 器:代表函数 装饰:装饰其他函数 装饰器原则: 不能修改被装饰函数的源代码 不能修改被装饰函数的调用方式 实现装饰器: 1 函数即变量 (匿名函数没有函数名,使用完就会被回收) 2 高阶函数 a:把一个函数名当做实参传给另外一个函数 b:返回值中包含函数名 3 嵌套函数 a:在函数体内用d 阅读全文
posted @ 2017-12-21 13:22 安慧桥没有你 阅读(159) 评论(0) 推荐(0) 编辑