How to import python class #807
-
I try to get the class in python lib, the code is as follows from python import Python
fn main():
try:
let pydantic = Python.import_module("pydantic")
print(pydantic.BaseModel)
except e:
print("failed to show plot:", e.value) but get this error failed to show plot: An error occurred in Python. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Did you |
Beta Was this translation helpful? Give feedback.
-
In the except clause, I just did
so, mojo's # this is python
import pydantic as pd
print(str(pd.BaseModel)) From the python docs
In mojo, the print function works with mojo types, though it does have an overloaded type for But you can try this workaround
|
Beta Was this translation helpful? Give feedback.
In the except clause, I just did
print(e.value)
and I got this error (using python 3.11.5)so, mojo's
print
is not the same as python'sprint
. In python, theprint()
function will implicitly do something like thisFrom the python docs
In mojo, the print function works with mojo types, though it does have an overloaded type for
object
. My guess is that the mojoprint
does…