0
点赞
收藏
分享

微信扫一扫

linux上文件复制的python代码实现3.py

每次都需要打开代码修改要复制的文件路径台麻烦,所以改用位置参数

#文件的复制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

举报

相关推荐

0 条评论