每次都需要打开代码修改要复制的文件路径台麻烦,所以改用位置参数
#文件的复制3.py
import sys
def copy(source,destination):
file_read1 = open(source,mode="rb")
file_write1 = open(destination,mode="wb")
while True:
data = file_read1.read(4096)
if len(data) == 0:
break
file_write1.write(data)
file_read1.close()
file_write1.close()
print("完成")
copy(sys.argv[1],sys.argv[2])
运行案例:
[root@node1 day3]# python3 cpy2.py /etc/hosts /opt/hosts #位置参数
完成
[root@node1 day3]# ls /opt/
1.txtx hostname hosts registries.conf
标签:sys,python,py,read1,write1,hosts,file,linux,data From: https://blog.51cto.com/u_15937426/6099057