2021-03-07

python 文件操作-古诗词复制

f=open("gushi.txt","w")

f.write("""床前明月光,
疑是地上霜,
举头望明月,
低头思故乡。
    """)
f.close()

def readGuShi():
    try:
        f = open("gushi.txt", "r")
        content = f.readlines()
        return content
    except IOError as result:
        print("文件打不开")
    finally:
        f.close()

def writeGushi(list1):
     try:
        f2=open("copy.txt","w")
        for temp in list1:
             f2.write(temp)
     except Exception as result1:
         print(result1)
     finally:
         f2.close()

my_list=readGuShi()
writeGushi(my_list)
print("复制完毕")

-课程链接

上一篇:JS闭包


下一篇:maplet, power set, domain subtraction,