Failed to import module written in C # using IronPython

I am currently struggling with writing IronPython modules in C #. First, I have some empty partial class that represents the base of the module:

[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'm trying to implement 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 now I want to use the module, it does not work:

import demo
Sql.executeNoneQuery("", "")

This throws an exception:

name 'Sql' not defined

Using

from demo import Sql
Sql.executeNoneQuery("", "")

Everything works perfectly. What did I really do wrong?

Many thanks!

+4
source share
1 answer

You should check the difference between import and import.

Demo.Sql . Demo.Sql.executeNoneQuery("", "")

+2

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


All Articles