Replies: 3 comments 2 replies
-
So I ended up adding a class method to add dictionary items as shown below. This works, but to me it's non-intuitive.
|
Beta Was this translation helpful? Give feedback.
-
For me, directly using from python import Python
fn use_dict() raises:
var dictionary = Python.evaluate("dict()") # Python.evaluate("{}") also works
dictionary.__setitem__("fruit", "apple")
dictionary.__setitem__("starch", "potato")
print("Fruit: ", dictionary["fruit"]) # Prints "Fruit: apple"
fn main() raises:
use_dict()
|
Beta Was this translation helpful? Give feedback.
-
create a Python dictionary object in Mojo, which one can be entered as an argument for Python users? Sample code provided by kapa.ai It doesn't work anymore. importing Python from python def use_dict(): invalid call to 'call': argument #1 cannot be converted from 'Dict[string, String]' to 'PythonObject' def getProjects(without self) calls -> String: Cancel the HTTP connection.var api_message = self._http.ApiMessage("get") |
Beta Was this translation helpful? Give feedback.
-
How can I create in Mojo a Python dictionary object that I can pass as an argument to a custom Python function?
When I pass a Mojo dictionary to my Python function, I get an error.
invalid call to '__call__': argument #1 cannot be converted from 'Dict[String, String]' to 'PythonObject'
And when I try to use a Python dictionary created from a custom class, Mojo flags an error:
expression must be mutable in assignment
Beta Was this translation helpful? Give feedback.
All reactions