我想在打电话时显示小时,date.now.hour
但出现此错误
AttributeError: 'function' object has no attribute 'hour'
这是我的代码:
#!/usr/bin/python
class Date:
def now(self):
self.hour = "hour"
print "Now"
def __call__(self, string):
print string
date = Date()
date('hello') # print hello
date.now.hour # print hour
我的任务是
制作一个可以做到这一点的类:
date.now()
- 输出:'now'
date('hai')
- 输出:'hai'
date.now
输出:'now'
date.now.hour
输出:'hour'