FAQ: Python in Pokitto

Hi!

Try umachine.time_ms()

its time_ms

Damn you @Hanski! :wink:

2 Likes

Thanks guys. That works. Finally I can make use of time :slight_smile:

That doesn’t mean the framerate counter is necessarily inaccurate,
you’d expect to have different running speeds for the simulator, the emulator and the actual hardware because they’re all different mechanisms and it’s probably not possible to get them that close to each other.

The value on hardware is the one that’s actually important.

(Although this does imply that maybe the frame rate limitation system might not be that accurate.)

I have now updated the FAQ and the uMachine reference with time_ms() info.

3 Likes

hi Guys
I wondering where can I find the filter/reduce functions in pokitto micropython? @Hanski
it complains like ‘filter is undefined’…

Just in case it doesn’t provide them, these should be valid implementations:

def filter(function, iterable):
	for item in iterable:
		if function(item):
			yield item;

def reduce(function, iterable):
	accumulator = None
	for item in iterable:
		# Probably breaks if an iterable returns None
		if previous != None:
			accumulator = function(accumulator, item);
		else
			accumulator = item

# Extra bonus?
def accumulate(function, iterable):
	previous = None
	for item in iterable:
		# Probably breaks if an iterable returns None
		if previous != None:
			yield function(previous, item);
		previous = item

# Bonus, because what's reduce without map? :P
def map(function, iterable):
	for item in iterable:
		yield function(item);

(They might be wrong - I’m not really a Python programmer, I just cobbled these together from a few minutes on the internet.)


Edit: realised I accidentally implemented accumulate instead of reduce. (I’m used to these functions having different names.) On the bright side, that’s another bonus function.

It’s worth noting that all these functions will be less efficient than versions implemented in the C++ layer.

1 Like

hey, thank you for the quick response! :grinning:

2 Likes

Micropython is a subset of Python so might well be that those functions are just not implemented in MP core.

2 Likes