object __*attr__ methods

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
pagano.paganino
Posts: 89
Joined: Fri Sep 11, 2015 10:47 pm
Location: Italy

object __*attr__ methods

Post by pagano.paganino » Mon Nov 28, 2016 2:50 pm

Hi folks,
if someone can found useful to have:

Code: Select all

__getattr__
__delattr__
__setattr__
i have attached .path files to implement this.

https://github.com/micropython/micropyt ... -263289328

test:

Code: Select all

def test():

    class B(object):
        def __init__(self):
            print("__init__")

        def __getattr__(self, name):
            print("__getattr__", name)
            return super(B, self).__getattr__(name)

        def __setattr__(self, name, value):
            print("__setattr__", name, value)
            super(B, self).__setattr__(name, value)

        def __delattr__(self, name):
            print("__delattr__", name)
            super(B, self).__delattr__(name)

    b = B()
    b.a = "c"
    print(b.a)
    del b.a

    try:
        print(b.a)
    except AttributeError:
        print("AttributeError")

if __name__ == "__main__":
    test()
Regards.
Attachments
obj_attrs.zip
(1.69 KiB) Downloaded 205 times

Post Reply