# -*- coding = utf-8 -*-
# @Time : 2022/7/23 11:09
# @Author : khm
# @File : file.py
# @Software : PyCharm
import os
import shutil
def writeFile(str):
try:
f = open("text.txt", "w")
try:
f.write(str)
finally:
f.close()
except Exception as result:
print(result)
shutil.copyfile("text.txt", "a.txt")
def readFile():
try:
f = open("a.txt", "r")
try:
while True:
content = f.readline()
print(content)
if len(content) == 0:
break
finally:
f.close()
except Exception as result:
print(result)
writeFile("1\n2\nwojiuzhiaini\ndkwakgd")
readFile()
Python文件操作-读取
最新推荐文章于 2024-07-25 00:08:05 发布