from js import createObject # name the javascript function, to call from python from pyodide.ffi import create_proxy # import create_proxy function from pyscript import Element # import Element object to see html elements import datetime # inport datetime library # call the javascript function createObject we defined and imported # create a javascript object named pyGlobals, link it to pyscript global names # all global variable and function names will be made visible to javascript createObject( create_proxy( globals( )), "pyGlobals" ); # define global function named current_time() def current_time(): # note must use python indentation # declare local variable tm and initialise it with the system time tm = datetime.datetime.now( ); # Get paragraph element by id and write the current time to it paragraph = Element("current-time"); paragraph.write( tm.strftime( "%Y-%m-%d %H:%M:%S" )); # return the formatted time string as the result of current_time() return tm.strftime( "%Y-%m-%d %H:%M:%S" );