Python--复制某个文件的内容到另一个文件中

import os.path
import sys
def main():
    f1 = input("Enter a source file:").strip()
    f2 = input("Enter a targe file:").strip()
    if os.path.isfile(f2):
       print(f2 + "already exists")
       sys.exit()
    infile = open(f1, "r")
    outfile = open(f2, "w")
    countlines = countchars = 0
    for line in infile:
        countlines +=1
        countchars +=len(line)
        outfile.write(line)
    print(countlines, "lines and", countchars, "chars copied")
    infile.close()
    outfile.close()
main()


你可能感兴趣的:(File,enter,source,already)