python - Why does my class raise an AttributeError? -
I can be blind, but I can not really see why this class fails: < Blockquote>
AttributeError: DataTime Import TimeDelta Class in the Next Sandwich Event NextSunday (): Datetime Import Datetime from DataTime Import Time from Def __init __ (Self, Trigger = 1) An attribute 'Trigger' from datetime '
none): "" "Get the date, and until next Sunday, until the following Sunday. Logic: -` trigger ': an extra week which Hen If the number of days is less than the trigger. "" "Self.str = u '% s% S days)% (Swdeti). Date (), self No_de ()) self.trigger = trigger dig __incodes __ (self): return self. RRF __str __ (self): Return Unicode (self) encode ('utf-8') def __repr __ (self): Return '& lt; Next Sunday: '+ self .str +' & gt; Def no_days (self): "" "Get the next Sunday date." "Day" = no limit to (7): dt = datetime.now () + timedelta (days = i) if dt.weekday () = 6: days = i # add another week if less days are left Trigger if self.trigger: if days & lt; Self.trigger: day + = 7 return day def date (self): #datetime obj happens next Sunday, but current time dt_of_next_sun = datetime.now () + timedelta (day = self.no_days ()) #date_of_next_sun (Dt_of_next_sun.date), time (23, 59) P> You have to switch to self.str = u '% s (% s day)'% (Swadet). Date (), self No_days () self.trigger = trigger like this
self.trigger = trigger self.str = u '% s (% s day) '% (Self-data). Date (), self No_de ()) Because the no_days method otherwise becomes before self.trigger attribute . This is bad because try to read the value of the no_days method self.trigger attribute: If self.trigger: if days & LT; Self.trigger:
Comments
Post a Comment