2
새해 복 많이 받으세요!Python 클래스 상속
저는 파이썬을 처음 사용하고 있으며, 클래스 상속을 실험 해 왔습니다. 아래 코드를 작성하고 몇 가지 질문이 있습니다.
- shDate3 대신 numpy.datetime64 유형의 shDate3이있는 이유는 무엇입니까? shDate는 SHDate 유형 인 것 같습니다. 이는 예상했던 동작입니다.
- 왜 shDate2를 만들 수 없습니까? ''정수가 필요합니다 ''오류가 발생했습니다 ...
고마워요!
from datetime import *
from numpy import *
class SHDate(date):
def __init__(self, year, month, day):
date.__init__(self, year, month, day)
class SHDate2(date):
def __init__(self, dateString):
timeStruct = strptime(dateString, "%Y-%m-%d")
date.__init__(self, timeStruct.tm_year, timeStruct.tm_mon, timeStruct.tm_mday)
class SHDate3(datetime64):
def __init__(self, dateString):
super(SHDate3, self).__init__(dateString)
if __name__ == '__main__':
shDate = SHDate(2010,1,31)
print type(shDate)
shDate3 = SHDate3("2011-10-11")
print shDate3
print type(shDate3)
shDate2 = SHDate2("2011-10-11")
print shDate2