版权声明:转载请注明出处 https://blog.csdn.net/qq_42292831/article/details/89402069
>>> with open(xxx,"xx",encoding="XXX") as f:
【The way to handle your file】
【 Attention 】
1. When we open file as f:
"f" can not be visited directly, it is iterable, and it is same between " for line in f.readlines(): " and " for line in f: "
2. f.read() will read whole file as a string .
str1 = ["abcdefg","sdd","1212"]
str1_deal = "".join(str1)
print(str1_deal.split("d"))
data = "N-dimensional Space!"
with open("abcd.txt","a+",encoding="UTF-8") as f:
f.write(data)
for line in f:
print(line)
with open("abcd.txt","r",encoding="UTF-8") as f:
for line in f:
print(line.strip().split())