一、语法
1 sys.argv 命令行参数List,第一个元素是程序本身路径
2 sys.exit(n) 退出程序,正常退出时exit(0)
3 sys.version 获取Python解释程序的版本信息
4 sys.maxint 最大的Int值
5 sys.path 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
6 sys.platform 返回操作系统平台名称
二、文件拷贝
# src_file=sys.argv[1]
# dst_file=sys.argv[2]
# # 判断
#
# with open(r'%s' %src_file,mode='rb') as read_f,
# open(r'%s' %dst_file,mode='wb') as write_f:
# for line in read_f:
# write_f.write(line)
三、打印进度条
import time
def progress(percent):
if percent > 1:
percent = 1
res = int(50 * percent) * '#'
print('
[%-50s] %d%%' % (res, int(100 * percent)), end='')
recv_size=0
total_size=1025011
while recv_size < total_size:
time.sleep(0.01) # 下载了1024个字节的数据
recv_size+=1024 # recv_size=2048
# 打印进度条
# print(recv_size)
percent = recv_size / total_size # 1024 / 333333
progress(percent)