标签:int read while mode 获取 模块 span nbsp 进阶
import sys # python3 run.py 1 2 3 # sys.argv 获取的是解释器后的参数值 print(sys.argv)
src_file = input(‘原文件路径:‘).strip() dst_file = input(‘新文件路径:‘).strip() 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)
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) # 在run.py所在的文件夹下,按住shift,右键,选择“在此处打开power shell”,输入 # 格式:python3 run.py 原文件路径 新文件路径 # python3 run.py D:\1.docx D:\2.docx #拷贝成功
# print(‘[%-50s]‘ %‘#‘) # print(‘[%-50s]‘ % ‘##‘) # print(‘[%-50s]‘ % ‘###‘) # 输出: [# ] [## ] [### ] import time res = ‘‘ for i in range(50): res += ‘#‘ time.sleep(0.2) print(‘\r [%-50s]‘ % res, end=‘‘) # 输出: [##################################################]
import time recv_size = 0 total_size = 25600 while recv_size < total_size: # 模拟网速 time.sleep(0.2) # 下载了1024个字节的数据 recv_size += 1024 # 打印进度条 # print(recv_size) percent = recv_size / total_size # 1024 / 25600 if percent > 1: percent = 1 res = int(50 * percent) * ‘>‘ print(‘\r [%-50s] %d%%‘ % (res,percent*100), end=‘‘)
import time def progress(percent): if percent > 1: percent = 1 res = int(50 * percent) * ‘>‘ print(‘\r [%-50s] %d%%‘ % (res,percent*100), end=‘‘) recv_size = 0 total_size = 25600 while recv_size < total_size: time.sleep(0.2) recv_size += 1024 percent = recv_size / total_size # 1024 / 25600 progress(percent)
标签:int read while mode 获取 模块 span nbsp 进阶
原文地址:https://www.cnblogs.com/zhww/p/12984017.html