mojo编程语言:mojo调用python库及内置函数builtins

发布时间 2023-09-27 21:50:46作者: Angry_Panda

编程语言mojo调用python十分方便,mojo不仅可以调用python的库函数更可以调用python的内置函数(builtins),给出示例代码:

from python import Python


fn main() raises:
    Python.add_to_path(".")
    let mypython = Python.import_module("xyz")

    let x = mypython.hello()
    print(x)


    let foo = Python.import_module("builtins").input()
    print(foo)

 

其中 xyz.py 文件内容:

def hello():
    print("hello world")

 

 

===========================================

 

 

代码文件结构:

 

 

 

运行效果:

 

 

注意:这里的abcdef是人为手动输入及自动输出的。

 

 

===========================================