IronPython importing modules

I follow the example from the best answer here on T, compiling with Pyc.py.

Compile Python scripts and calling methods from C #

I get an exception in pyScope = pyEngine.ImportModule("MyClass");

no module named MyClass

I believe that this is a mistake, because sometimes recompiling with Pyc.py will lead to the detection of the ImportModule dll, but in other cases it is not.

CONCLUSION: As indicated below by digEmAll, compiling modules with Pyc.py for use in this way gives random results. Call clr.CompileModules manually.

+3
source share
1 answer

OK, I get it.

A module name is (case sensitive) the name of the source .py module, not a compiled dll.

, myClass.py, MyClass.dll, ImportModule("myClass") not ImportModule("myClass")


EDIT:

:

import clr
clr.CompileModules("CompiledScript.dll", "script.py")

, pyc.py, dll __main__ .py.

...

IIRC, python __main__, (.. ), ...

+7

Source: https://habr.com/ru/post/1764587/


All Articles