5

I am trying to create a function that takes in any object and prints it if it is _Printable, and prints "object" otherwise.

To do this I am trying to use @paramter if to check the type at compile time to choose the right printing code:

@always_inline
fn try_print[Type: AnyType](obj: Type):
    @parameter
    if isinstance(obj, _Printable):
        print_no_newline(obj)
    else:
        print_no_newline("object")

But it seems the way to check types in Mojo is different than Python because it throws an error saying isinstance does not exist, and I cannot find a way to do it in Mojo on their online module directory or programming guides.

Essentially: What is Mojo's alternative to Python's isinstance?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.