|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 1059389705 于 2019-12-1 20:02 编辑 import time as t
class Record:
def __init__(self,value=None,name=None):
self.na = name
self.val = value
self.time = []
self.unit = ['年','月','日','时','分','秒']
self.prompt = '于北京时间'
def __get__(self,instance,owner):
self._timer()
return self.val
def __set__(self,instance,value):
self.val = value
self._timer()
def _timer(self):
current = t.localtime()
f = open('D:\\record.txt','a',encoding = 'utf-8')
for index in range(6):
self.prompt += str(self.time.append(current[index])) + self.unit[index]
print(self.prompt)
f.write('%s变量 %s 被修改 %s = %s \n '% (self.na,self.prompt,self.na,str(self.val)))
f.close()
#初始化prompt
self.prompt = '于北京时间
class Test:
x = Record(10,'x')
y = Record(8.8,'y')
应该这样改:
import time as t
class Record:
def __init__(self,value=None,name=None):
self.na = name
self.val = value
self.time = []
self.unit = ['年','月','日','时','分','秒']
self.prompt = '于北京时间'
def __get__(self,instance,owner):
self._timer()
return self.val
def __set__(self,instance,value):
self.val = value
self._timer()
def _timer(self):
current = t.localtime()
f = open('E:\\record.txt','a',encoding = 'utf-8')
for index in range(6):
self.prompt += str(current[index]) + self.unit[index]
print(self.prompt)
f.write('%s变量 %s 被修改 %s = %s \n '% (self.na,self.prompt,self.na,str(self.val)))
f.close()
#初始化prompt
self.prompt = '于北京时间'
|
|