NixonInnes
NixonInnes
MModular
Created by NixonInnes on 8/17/2024 in #questions
Struct wrapping Python object
This seems to work, although I would prefer to use fn over def so I can understand / use static typing here
from python import Python, PythonObject

struct Window:
var _window: PythonObject

fn __init__(inout self):
try:
self._window = Window.get_window()
except e:
print("Failed to create window:", str(e))
self._window = None


@staticmethod
def get_window() -> PythonObject:
var window_module = Python.import_module("window")
return window_module.Window()
from python import Python, PythonObject

struct Window:
var _window: PythonObject

fn __init__(inout self):
try:
self._window = Window.get_window()
except e:
print("Failed to create window:", str(e))
self._window = None


@staticmethod
def get_window() -> PythonObject:
var window_module = Python.import_module("window")
return window_module.Window()
6 replies