diff --git a/src/runtime/PythonTypes/PyModule.cs b/src/runtime/PythonTypes/PyModule.cs index 243f77ecc..bb539373d 100644 --- a/src/runtime/PythonTypes/PyModule.cs +++ b/src/runtime/PythonTypes/PyModule.cs @@ -59,6 +59,22 @@ internal PyModule(BorrowedReference reference) : this(new NewReference(reference { } + /// + /// Set Variable Method + /// + /// + /// Add a new variable to the variables dict if it not exist + /// or update its value if the variable exists. + /// + public PyModule Set(string name, object? value, Type type) + { + if (name is null) throw new ArgumentNullException(nameof(name)); + + using var _value = Converter.ToPython(value, type); + SetPyValue(name, _value.Borrow()); + return this; + } + /// /// Given a module or package name, import the module and return the resulting object. ///