Skip to content

How to import python class #807

Closed Locked Answered by rarebreed
tqq1994516 asked this question in Q&A
Sep 15, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

I can print pydantic variable object,but if me print pydantic.BaseModel, I will get this error.

In the except clause, I just did print(e.value) and I got this error (using python 3.11.5)

❯ mojo run main.mojo
No string method found on the python object.

so, mojo's print is not the same as python's print. In python, the print() function will implicitly do something like this

# this is python
import pydantic as pd
print(str(pd.BaseModel))

From the python docs

All non-keyword arguments are converted to strings like str() does and written to the stream

In mojo, the print function works with mojo types, though it does have an overloaded type for object. My guess is that the mojo print does…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@tqq1994516
Comment options

@tqq1994516
Comment options

Comment options

You must be logged in to vote
1 reply
@tqq1994516
Comment options

Answer selected by tqq1994516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants