def add_lookup(cls):
varnames = filter(str.isupper, cls.__dict__.keys())
lookup = dict(map(lambda varname: (cls.__dict__.get(varname, None), varname), varnames))
setattr(cls, 'lookup', lookup)
return cls
Guys,
Please help me to convert this function for MicroPython. Thanks a lot. There is no __dict__ function built in.
Get Attribute of a Class
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Get Attribute of a Class
MicroPython lacks some of the "introspection" capabilities of CPython in the interests of keeping it "Micro". See https://github.com/micropython/micropyt ... ifferences.
You might like to experiment with:
You might like to experiment with:
Code: Select all
def add_lookup(cls):
varnames = filter(str.isupper, dir(cls))
lookup = dict(map(lambda varname: (getattr(cls, varname), varname), varnames))
setattr(cls, 'lookup', lookup)
return cls
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Get Attribute of a Class
Thank you Peter, appreciated.