Skip to content

How to import dependency for the functions? #3862

Closed Answered by adamreichold
k82cn asked this question in Questions
Discussion options

You must be logged in to vote

I did not compile or test this, but it should go something like

let main = py.import("__main__")?;
let globals = main.dict();

let random = py.import("random")?;
globals.set_item("random", random)?;

let math = py.import("math")?;
globals.set_item("math", math)?;

Note that this is in no way scoped to the current invocation of task_fn, it will affect the global state of the embedded Python interpreter. (But your task function will not be isolated anyway if they share that single embedded interpreter.)

Replies: 2 comments 12 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
12 replies
@k82cn
Comment options

@adamreichold
Comment options

@k82cn
Comment options

@adamreichold
Comment options

Answer selected by k82cn
@k82cn
Comment options

@k82cn
Comment options

@adamreichold
Comment options

@k82cn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants