Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:11:57+00:00 2026-06-13T18:11:57+00:00

I might be blind, but I really can’t see why this class fails with:

  • 0

I might be blind, but I really can’t see why this class fails with:

AttributeError: NextSunday instance has no attribute ‘trigger’

from datetime import datetime
from datetime import time
from datetime import timedelta


class NextSunday():
    def __init__(self, trigger=None):
        """
        Get date of, and number of days until, next Sunday.

        Arguments:
        - `trigger`: Add an extra week if less than trigger number of days.
        """
        self.str = u'%s (%s days)' % (self.date().date(), self.no_days())
        self.trigger = trigger

    def __unicode__(self):
        return self.str

    def __str__(self):
        return unicode(self).encode('utf-8')

    def __repr__(self):
        return '<Next Sunday: ' + self.str + '>'

    def no_days(self):
        """Get date of next sunday. """
        days = None
        for i in range(7):
            dt = datetime.now() + timedelta(days=i)
            if dt.weekday() == 6:
                days = i

        # Add another week if there are less days left then trigger
        if self.trigger:
            if days < self.trigger:
                days += 7

        return days

    def date(self):
        # The datetime obj contains the next sunday, but also the current time
        dt_of_next_sun = datetime.now() + timedelta(days=self.no_days())

        # Get the whole day
        date_of_next_sun = datetime.combine(dt_of_next_sun.date(),
                                            time(23, 59))

        return date_of_next_sun
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:11:58+00:00Added an answer on June 13, 2026 at 6:11 pm

    You need to switch these

        self.str = u'%s (%s days)' % (self.date().date(), self.no_days())
        self.trigger = trigger
    

    like this

        self.trigger = trigger
        self.str = u'%s (%s days)' % (self.date().date(), self.no_days())
    

    because otherwise the no_days method is called before the self.trigger attribute is created. This is bad because the no_days method tries to read the value of the self.trigger attribute:

    if self.trigger:
        if days < self.trigger:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple question but I've searched and searched and can't find
This might be a very vague question but I guess I don't really understand
This question has come up a lot but I can't make it work. I
This might seem like a very easy question for some of you folks, but
Not really a programming question, but I can't think of anywhere else to ask.
I'm hoping that someone else has experienced this and can point me in the
First let me apologize for the scale of this problem but I'm really trying
I might be blind on both eyes, but iterating through a lot of versions
Might be my question sounds more naive. But I wanted to know if it
Might be my question is abstract or out of context, but i am asking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.