Python sys和shutil模块

 1 # !/user/bin/python
 2 # -*- coding: utf-8 -*-
 3 import sys
 4 
 5 # version 获取版本信息
 6 sys.version
 7 
 8 
 9 # maxint 支持的最大int值
10 sys.maxint
11 
12 
13 # argv 获取当前脚本的所有参数
14 sys.argv
 1 # !/user/bin/python
 2 # -*- coding: utf-8 -*-
 3 
 4 import shutil
 5 
 6 # shutil 模块是高级的文件,文件夹,压缩包处理模块
 7 # shutil.copyfileobj
 8 
 9 f1 = open('a.txt',encoding='utf-8')
10 f2 = open('b.txt','w',encoding='utf-8')
11 
12 shutil.copyfileobj(f1,f2)
13 
14 
15 # shutil.copyfile
16 shutil.copyfile('a.txt','b.txt')  # 源码中已经包含了open的动作和shutil.copyfileobj的动作
17 
18 
19 # shutil.copymode 仅复制权限. 内容/属组/用户均不变 TODO 需要在linux平台上测试
20 
21 
22 # shutil.copy(src, dst), 同时把文件和权限都复制过去
23 
24 
25 # shutile.copytree  复制文件树型结构
26 
27 # shutil.rmtree 删除目录 (有点类似于os里的递归删除目录, os.removedir, 有什么区别? TODO 0
28 
29 
30 # shutil.make_archive (base_name, format,...) 创建压缩包, 并返回文件路径
31 
32 
33 import zipfile  # 可以单独一个文件一个文件地压缩
34 z=zipfile.ZipFile('day4.zip','w')
35 z.write('p_test.py')
36 print('-------------')
37 z.write('a.txt')
38 z.close

猜你喜欢

转载自www.cnblogs.com/cheese320/p/9059621.html