Repository navigation
Environment
DetailsI compiled the following code to namespace CalcTest
{
public static class Calculator
{
public static int Add(int a, int b)
{
return a + b;
}
}
}Then I tried importing the class import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent / "DLLs"))
import clr
clr.AddReference("CalcTest")
from CalcTest import Calculatorand I obtained the following error: Following the tutorial How To Call A Dynamic Library I changed the namespace in C# to from CalcTestNS import Calculatorand it worked. In the tutorial it is not mentioned that the namespace and the assembly cannot have the same name. It would be a great time-saver to document this. |
Answered by
filmor
Jul 17, 2024
Replies: 1 comment 2 replies
|
It's not mentioned because it's not true. For Python scripts, the current path is implicitly added to |
2 replies
Answer selected by
mardukbp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not mentioned because it's not true. For Python scripts, the current path is implicitly added to
sys.pathand thus the directoryCalcTestis loaded as a namespace package. Rename it and it will be loaded properly.