标签:nes class 读一行 span open 循环 文件 file bsp
1 写文件
my_list = ["1", "2", "3"] my_file = open("myfile.txt", "w") for item in my_list: my_file.write(item + "\n")
my_file.writelines(my_list) // 写多个 my_file.close()
2 读文件
my_file = open("myfile.txt", "r") print(my_file.read()) // 一次性读取整个文件 my_file.close() my_file = open("myfile.txt", "r") print(my_file.readline()) // 读一行 print(my_file.readline()) // 再读下一行 my_file.close()
3 循环读取文件
my = open("myfile.txt") for line in my: print(line + " aaa ")
标签:nes class 读一行 span open 循环 文件 file bsp
原文地址:https://www.cnblogs.com/liufei1983/p/9866429.html