Python Forum
how to get around recursive method call
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to get around recursive method call
#2
Do you mean to use __getattribute__
class YourObject:
    def __getattribute__(self, name):
        print(f'attribute {name}')
        return object.__getattribute__(self, name)


your_instance = YourObject()
your_instance.this = 'This'
print(your_instance.this)
Output:
attribute 'this' This
Note: __getattr__ is called when there is no attribute
https://docs.python.org/3/reference/data..._getattr__ Wrote:object.__getattr__(self, name)
Called when the default attribute access fails with an AttributeError (either __getattribute__() raises an AttributeError because name is not an instance attribute or an attribute in the class tree for self; or __get__() of a name property raises AttributeError). This method should either return the (computed) attribute value or raise an AttributeError exception.

Note that if the attribute is found through the normal mechanism, __getattr__() is not called. (This is an intentional asymmetry between __getattr__() and __setattr__().) This is done both for efficiency reasons and because otherwise __getattr__() would have no way to access other attributes of the instance. Note that at least for instance variables, you can fake total control by not inserting any values in the instance attribute dictionary (but instead inserting them in another object). See the __getattribute__() method below for a way to actually get total control over attribute access.
Reply


Messages In This Thread
RE: how to get around recursive method call - by Yoriz - Jun-29-2020, 09:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  method call help sollarriiii 6 1,324 Feb-21-2023, 03:19 AM
Last Post: noisefloor
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,728 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  list call problem in generator function using iteration and recursive calls postta 1 2,030 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Return boolean from recursive class method medatib531 6 3,690 Jul-13-2020, 04:27 AM
Last Post: medatib531
  How to call COM-method using comtypes jespersahner 0 2,519 Nov-15-2019, 12:54 PM
Last Post: jespersahner
  Polymorphism not working with a call to a abstract method colt 3 2,426 Nov-04-2019, 11:04 PM
Last Post: colt
  How to Call a method of class having no argument dataplumber 7 6,754 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  Call method from another method within a class anteboy65 3 7,679 Sep-11-2019, 08:40 PM
Last Post: Larz60+
  What is the use of call method and when to use it? everyday1 1 3,389 Jul-14-2019, 01:02 PM
Last Post: ichabod801
  I'm trying to figure out whether this is a method or function call 357mag 2 2,532 Jul-04-2019, 01:43 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020