新手问题:如何在调用变量时打印变量的当前值,而不是在首次定义时获取其旧值?
epoch = int(time.time()*1000)
print epoch
time.sleep(2)
print epoch # it should now be 2 seconds larger, but isn't.
请您参考如下方法:
您必须为此创建一个函数。这样的东西就足够了吗?
epoch = lambda: int(time.time()*1000)
print epoch()
time.sleep(2)
print epoch()
您也可以将它封装到一个类中,并从中创建一个@property,这样您就可以在不使用括号 ()
