【发布时间】:2017-03-22 09:19:09
【问题描述】:
我的 python 脚本需要帮助。如何通过 Date 的类访问我的时钟功能?
from datetime import date
from datetime import datetime
class Date(object):
def date_today(self):
now = date.today()
print (now)
class Time(Date):
pass
def clock(self):
hr = datetime.now()
hr_now = hr.hour
print (hr_now)
cr_date = Date()
print (cr_date.date_today())
print (cr_date.date_today.clock())
我收到一个错误 --> AttributeError: 'function' object has no attribute 'clock'。这个错误的原因是什么?
【问题讨论】:
-
是的,你的 Date 类没有 clock() 函数。
-
我有2个类,日期类和时间类我只想通过日期类访问时间类,你有什么建议吗?
标签: python python-3.x class subclassing