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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:50:12+00:00 2026-06-06T07:50:12+00:00

I have the declared a class in following way class A: def __init__(self, list_1,

  • 0

I have the declared a class in following way

class A:
    def __init__(self, list_1, list_2):
        self.list1 = list_1
        self.list2 = list_2

    def __getattr__(self, item):
        if item in self.list1: return "It is in list 1"
        elif item in self.list2: return "It is in list 2"
        else: return "It is in neither list 1 nor list 2"

Here when I am adding __setattr__ self.list1 goes recursive, since __getattr__ get called after every self.list1 and this recursion is unstoppable. Can you please help me out with it. I need to implement like this.

Thanks

  • 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-06T07:50:13+00:00Added an answer on June 6, 2026 at 7:50 am

    First of all, this is a totally bizarre usage of __getattr__, but I’ll assume that you know that.

    Basically, the problem is that __setattr__ is always called every time you do something like self.foo = bar, so if you use that within __setattr__ you’ll end up with the recursion that you got. What you need to do is insert the value that you’re trying to set directly into __dict__ self.__dict__['foo'] = bar.

    If you’re using new style classes (i.e. A is a descendant of object), then you could also do super(A, self).__setattr__(item, value) or even just object.__setattr__(self, item, value)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following template method declared in my interface: class IObjectFactory { public:
I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
I have declared a class as class DCFrameListener : public FrameListener, public OIS::MouseListener, public
WorkAround: I have declared a class level Public static variable and initialized with a
I have declared C++/CLI class as below namespace testcominterface { [ComVisible(true)] [Guid(FFCA805F-8DAB-4AF8-A7B7-B488136E8177)] public interface
I have a class declared as: public class Foo<T> : Panel where T :
Let's say I have a class declared as: @class SomeClass @interface SomeClass: NSObject {
If I have a java class which is package-private (declared with class, not public
I have an abstract method in a base class declared like so... public abstract
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need

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.