4

Currently i'm struggeling with writing IronPython modules in c#. 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

When using

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

Everything works just fine. What did i do actualy wrong?

Thank you very much!

BendEg
  • 20,098
  • 17
  • 57
  • 131

1 Answers1

2

You should check the difference between import and from import

Demo.Sql is needed in the first case. So try Demo.Sql.executeNoneQuery("", "") instead

Community
  • 1
  • 1
Fab
  • 14,327
  • 5
  • 49
  • 68
  • Ok, this makes sense. If IP would do it as i expected it, `import Demo` would be the same as `from Demo import *`, or not? – BendEg Dec 29 '15 at 14:35