[英]Could not import module written in c# with IronPython
Currently i'm struggeling with writing IronPython modules in c#. 目前我正在编写在c#中编写IronPython模块。 At first i have some empty partial class, which represents the module base: 起初我有一些空的部分类,它代表模块基础:
[assembly: PythonModule("demo", typeof(Demo.IronPythonAPI.PythonAPIModule))]
namespace Demo.IronPythonAPI
{
/// <summary>
/// Demo api module root/base
/// </summary>
public static partial class PythonAPIModule
{
}
}
In some other files, i try to implement the modules: 在其他一些文件中,我尝试实现模块:
namespace Demo.IronPythonAPI
{
/// <summary>
/// Python api module path root (~import demo)
/// </summary>
public static partial class PythonAPIModule
{
/// <summary>
/// Python SQL-Module
/// </summary>
[PythonType]
public static class Sql
{
public static int executeNoneQuery(string query, string conName)
{
Console.WriteLine("Hello World");
return 0;
}
}
}
}
If i now want to use the module, it does not work: 如果我现在想要使用该模块,它不起作用:
import demo
Sql.executeNoneQuery("", "")
This throws the exception: 这引发了异常:
name 'Sql' is not defined 名称'Sql'未定义
When using 使用时
from demo import Sql
Sql.executeNoneQuery("", "")
Everything works just fine. 一切正常。 What did i do actualy wrong? 我做错了什么?
Thank you very much! 非常感谢你!
You should check the difference between import and from import 您应该检查导入和导入之间的区别
Demo.Sql is needed in the first case. 在第一种情况下需要Demo.Sql 。 So try Demo.Sql.executeNoneQuery("", "")
instead 所以请尝试使用Demo.Sql.executeNoneQuery("", "")
代替
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.