Python 读写同一配置文件
import os
################################################################
# 读写同一个文件,需要注意:关闭后,再写
#################################################################
def ReadNumpyFile():
num = ""
f_path = os.path.join(os.path.dirname(__file__),"num.ini")
with open(f_path, mode="r", encoding='utf-8') as f_data:
lines = f_data.readlines()
print(lines[0])
f_data.close()
with open(f_path, mode='w',encoding='utf-8') as f_w:
num = int(lines[0]) +1
print(num)
f_w.write(str(num))
return lines