Search found 65 matches

by ttmetro
Tue Mar 05, 2019 12:32 am
Forum: General Discussion and Questions
Topic: Dynamically add method to instance
Replies: 7
Views: 328

Re: Dynamically add method to instance

Yes, that's what I want: from types import MethodType class DynamicTest: def __init__(self): self.x = 5 def a(self): return self.x dt = DynamicTest() def b(self): return self.x dt.b = b def c(self): return self.x setattr(dt, 'c', MethodType(c, dt)) print('a', dt.a()) # print('b', dt.b()) print('c', ...
by ttmetro
Mon Mar 04, 2019 2:54 am
Forum: General Discussion and Questions
Topic: Dynamically add method to instance
Replies: 7
Views: 328

Re: Dynamically add method to instance

yes!

Also what I found with a web search is that this is exactly what

Code: Select all

MethodType
is for.
by ttmetro
Sun Mar 03, 2019 7:57 pm
Forum: General Discussion and Questions
Topic: Dynamically add method to instance
Replies: 7
Views: 328

Re: Dynamically add method to instance

I don't think that binds it to the instance. Hence no reference to "self".

I used a global as a workaround. Not pretty, but works.
by ttmetro
Sun Mar 03, 2019 1:09 am
Forum: General Discussion and Questions
Topic: Dynamically add method to instance
Replies: 7
Views: 328

Dynamically add method to instance

How do I add a function dynamically to a MicroPython object?

In standard python "MethodType" is used for this, but it seems missing from MicroPython. Is there a workaround?

Thanks,
Bernhard
by ttmetro
Sat Feb 16, 2019 10:01 pm
Forum: General Discussion and Questions
Topic: MicroPython on ParticleIO Argon ESP32
Replies: 2
Views: 146

Re: MicroPython on ParticleIO Argon ESP32

No.
The nRF is running MicroPython itself. This is how I access the esp32 which is not directly accessible (Making debugging harder).
by ttmetro
Sat Feb 16, 2019 9:06 pm
Forum: General Discussion and Questions
Topic: MicroPython on ParticleIO Argon ESP32
Replies: 2
Views: 146

MicroPython on ParticleIO Argon ESP32

I've flashed esp32-20180511-v1.9.4.bin to the ESP32 on the ParticleIO Argon using Adafruit's mini-ESP tool. I've successfully flashed other binaries using this tool, so I expect (?) that it flashed MicroPython correctly also. The UART connection between the nRF52840 also seems fine. E.g. I can enter...
by ttmetro
Mon Nov 26, 2018 7:26 pm
Forum: Development of MicroPython
Topic: bound method type check
Replies: 2
Views: 222

Re: bound method type check

Works perfectly. Thanks!
by ttmetro
Sun Nov 25, 2018 8:55 pm
Forum: Development of MicroPython
Topic: bound method type check
Replies: 2
Views: 222

bound method type check

How do I check if an object is either a function or bound method?

Application is specifying an interrupt handler (which can be one of these two things). There is a macro to test for functions, but I could not find anything equivalent for methods.
by ttmetro
Mon Nov 19, 2018 7:37 pm
Forum: General Discussion and Questions
Topic: check if object is a generator
Replies: 3
Views: 216

Re: check if object is a generator

Thanks, works perfect!
by ttmetro
Fri Nov 16, 2018 9:57 pm
Forum: General Discussion and Questions
Topic: check if object is a generator
Replies: 3
Views: 216

check if object is a generator

How do I check if an object is a coroutine (generator) in micropython?

Code: Select all

from inspect import iscoroutine
is not available.

This appears to work, but (???):

Code: Select all

def iscoroutine(obj):
    return str(type(obj)) == "<class 'generator'>"