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 1020347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:09:15+00:00 2026-05-16T11:09:15+00:00

I have this method: def is_active(self): if self.is_current_node(): return True cur_children = self.get_children() while

  • 0

I have this method:

def is_active(self):
    if self.is_current_node():
        return True
    cur_children = self.get_children()
    while cur_children is not None:
        for child in cur_children:
            if child.is_current_node():
                return True
            raise Exception(child.display_name)
        cur_children = cur_children.get_children()
    return False

I put this method together and I put the raise Exception(child.display_name) to test out and “alert()” me to which child was being hit. The exception is never raised. You’d think that was because the function returned True on the if child.is_current_node() part. Well, if I replace the if part with this:

        for child in cur_children:
            if child.is_current_node():
                raise Exception(child.display_name)

It doesn’t raise the exception still. If I do this however:

        for child in cur_children:
            raise Exception(child.display_name)

The exception is raised. I’m so confused. I’m sure this is something ridiculous but I was up till 2 and I can’t think straight enough to wrap my tiny brain around this.

  • 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-05-16T11:09:15+00:00Added an answer on May 16, 2026 at 11:09 am

    Some ideas:

    cur_children = self._children
    while cur_children is not None:
    for child in cur_children:
    if child.is_current_node():
    return True
    raise Exception(child.display_name)
    cur_children = cur_children._children

    I assume that self._children contains multiple children: [A, B, C]

    Then, on the first loop, it will take A. Let’s assume that A has these children: [AA, AB, AC].

    Now, you do this: cur_children = cur_children._children. This means that now, instead of continuing with B from the inital [A, B, C], it will continue with AA, and so on.

    In this example, it will never reach B. Is this intended?


    What does your is_current_node() contains? Probably you forgot to return a value, so the result is always None, and bool(None) == False.


    Another idea: (recursion)

    def is_active(self):
    
        def check_children(children):
            for child in children:
                if child.is_current_node():
                    return True
                else:
                    if children._children:
                        return check_children(children._children)
            return False
    
        if self.is_current_node():
            return True
        return check_children(children)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains this class method: def self.get_event_record(row, participant) event =
I have code like this: class Debug(object): ... @property def ThreadAwareLogger(self): if not self.logger_instance_for_current_thread:
I have a controller method that is a little something like this: def suggestions
I have this method: scala> def foo(traversable: Traversable[{def toByte: Byte}]) = { | traversable.map(_.toByte)
i have this code: def some_method(): #i need to get some attrs :( return
I have a method like this in my RoR 3 app def buscar array
Let's say that I have a method that looks like this: def raise_if_client_status_error(xml_resp) #
I have a model with a decimal field. The output of: def special_method(self): return
I have methods in all of my models that look like this: def formatted_start_date
I have a bunch of python methods that follow this pattern: def delete_session(guid): conn

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.