Home | News | Documentation | Download

TPython usage:: how to import and use the module?

I’m trying to run in C++ a function declared in a python module but it’s not clear to me how can i access the imported module …
Ideally i would like to be able to do:

try:
    from alienpy import alien
except Exception as e:
    try:
        from xjalienfs import alien
    except Exception as e:
        print("Can't load alienpy, exiting...")
        sys.exit(1)

or at least

import alienpy.alien as alien

so far i could do only this:

root [0] auto import_status = TPython::Import("alienpy");
root [1] cout << import_status << endl;
1

but i did not found a documentation about how to continue from this point …
Thanks a lot!

Hello,

In order to import a module with TPython, please make sure the module is in the PYTHONPATH and then run TPython::Exec("import alienpy").

Thanks! Indeed the exec worked and then also with exec i can access the module.
Thanks!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.