How to use python built-in functions from mojo?

I can’t figure out how to use built-in python functions from mojo. Specifically, i want to wrap a numpy array around a mojo HostDevice, and i need the python memoryview() function for that. How to call it?
Python.memoryview() doesn’t work…

I tried an alternative way of wrapping using ctypes and numpy.ndarray() but it crashes. No built-in python functions were needed there.

If anyone had managed to wrap a mojo (unsafe) pointer to memory into a numpy array, please share your code.

If you want to use things from Python’s builtin module, try this:

from python import Python

def main():
  builtins = Python.import_module("builtins")
  print(builtins)
1 Like

Indeed, it works. Thanks!
Mentioning this in an article about python interop would be helpful. For instance Python integration | Modular should be a good place.

Could you maybe raise a Documentation issue on Github?

Done!
(and thanks)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.