请问为什么跟着网课做的,self.fileObj.write写不进去文件呢,错误信息为'NoneType' object has no attribute 'write'。网课的人写的就好使,求解答
import time
class Mylog():
# 属性
fileurl = './'
filename = str(time.strftime('%Y-%m-%d'))+'.log'
fileObj = None
# 方法
def __int__(self):
# 打开文件
self.fileObj = open(self.fileurl+self.filename,'a+',encoding='utf-8')
def wlog(self,s):
#准备输入开始写入
date = time.strftime('%Y-%m-%d %H:%M:%S')
msg = date+' '+s
# 写入
print(msg)
self.fileObj.write(msg)
def __del__(self):
#关闭打开的文件
self.fileObj.close()
w = Mylog()
w.wlog('你好')