美文网首页
笨方法学python 习题17

笨方法学python 习题17

作者: d1b0f55d8efb | 来源:发表于2017-07-07 16:01 被阅读0次
    from sys import argv
    from os.path import exists
    
    script, from_file, to_file = argv
    
    print ("Copying from %s to %s" % (from_file, to_file))
    
    # we could do these two on one line too, how?
    
    #打开第一个文件
    input = open(from_file)
    #输入文件读出的内容
    indata = input.read()
    
    print ("The input file is %d bytes long" % len(indata))
    print ("Does the output file exist? %r" % exists(to_file))
    print ("Ready, hit RETURN to continue, CTRL-C to abort.")
    
    #以写的形式打开第二个文件
    output = open(to_file, 'w')
    output.write(indata) #写入indata读出的内容
    
    
    print ("Alright, all done.")
    output.close()
    input.close()
    

    相关文章

      网友评论

          本文标题:笨方法学python 习题17

          本文链接:https://www.haomeiwen.com/subject/netrhxtx.html