class bank: def user_info(self): a=input('请输入用户信息:') # 不写encoding = 'utf-8'中文会乱码 with open('info.txt','w',encoding='utf-8') as f: f.write(a) def get_info(self): with open('info.txt','r',encoding='utf-8') as f: print(f.read()) # 实力化类并调用方法 # bank().user_info() bank().get_info()
代码运行结果:
D:\py学习01\venv\Scripts\python.exe D:/py学习01/python基础/EX03.py
wiiofff非后方可
标签:info,文件,utf,encoding,python,用户,方法,bank From: https://www.cnblogs.com/xiaogan-520/p/17616292.html