I just started to play around with Mojo. I am having a hard time importing modules from the Python standard library even though, according to the examples reported in the quick start guide, importing Python's module should be a breeze. What am I missing?
For example, to import the "time" module, I have tried: let time = Python.import_module("time")
However, I get a couple of errors I don't get.
cannot call function that may raise in a context that cannot raiseuse of unknown declaration 'time', 'fn' declarations require explicit variable declarations
I have resolved the first error by adding raises to the function declaration and adding a try/except block to the import line. Although, I am not satisfied with this, it feels too verbose. Is there a better way?
I still don't have a solution for the second error. Can anyone suggest a solution?
fn main() raises:
#added raises and following try/except block
#to fix "Error 1"
from python import Python
try:
let time = Python.import_module("time")
except:
print('Import Error')
let s = time.time() #raises "Error 2"
print('Hello World')
let e = time.time()
print("Done in", e-s, "seconds")