English 中文(简体)
援引铁道星座
原标题:KeyNotFoundException on invoking IronPython

I need a MediaWiki parser in C#.
( http://www.mediawiki.org/wiki/Alternative_parsers )
Since there exists none, and I really want a MediaWiki parser and not some other, like WikiPlex, I was looking into using some of the existing parsers in another language, and was able to successfully invoke the kiwi parser to achieve this. However, the problem is it doesn t handle Unicode/UTF-8 correctly.

Now, I wanted to use this script:
http://www.connellybarnes.com/code/python/mw2html
and use it via IronPython.

I use IronPython 2.7 from here:
http://ironpython.net/

我下载了双月齐p文档(而不是安装器)。

Then I used this tutorial as base:
http://www.codeproject.com/KB/cs/IronPythonMethod_CShap.aspx

这是我做的:

using System;
using IronPython.Hosting;


namespace IronPythonMethodInvokationDemo
{


    class Program
    {


        // http://stackoverflow.com/questions/6557494/referencing-python-import-assemblies-when-calling-from-ironpython-in-c
        static void Main(string[] args)
        {


            //Microsoft.Scripting.Hosting.ScriptEngine m_engine = Python.CreateEngine(DefaultEngineOptions());
            Microsoft.Scripting.Hosting.ScriptEngine m_engine = Python.CreateEngine();
            System.Collections.Generic.ICollection<string> paths = m_engine.GetSearchPaths();

            paths.Add(@"D:usernameDocumentsVisual Studio 2010ProjectsIronPythonIronPython-Bin-2.7IronPython-2.7Lib"); // modules path
            paths.Add(@"D:usernameDocumentsVisual Studio 2010ProjectsIronPythonIronPython-Bin-2.7IronPython-2.7"); // ipy.exe path
            m_engine.SetSearchPaths(paths);


            //Step 1: 
            //Creating a new script runtime             
            //var ironPythonRuntime = Python.CreateRuntime();
            var ironPythonRuntime = m_engine.Runtime;

            try
            {
                //Step 2:
                //Load the Iron Python file/script into the memory
                //Should be resolve at runtime
                //dynamic loadIPython = ironPythonRuntime.UseFile("first.py");
                //ironPythonRuntime.GetBuiltinModule();
                dynamic loadIPython = ironPythonRuntime.UseFile("mw3html.py");

                //Step 3:
                //Invoke the method and print the result
                /*
                Console.WriteLine(
                                  string.Format("Addition result from IronPython method for {0} and {1} is {2}", 
                                  100,200, loadIPython.add(100, 200))
                                 );
                */

                Console.WriteLine( string.Format("Result for IronPython main method: {0}", loadIPython.main())  );
            } // End Try
            catch (System.IO.FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            } // End Catch
            Console.ReadKey(true);

        } // End Sub Main


    } // End Class Program


} // End Namespace IronPythonMethodInvokationDemo

If I use first.py, then everything works fine. Now, using mw2html.py, I get a

KeyNotFoundException on ironPythonRuntime.UseFile("mw3html.py"); for key "" ...

任何人都知道这意味着什么?

问题回答

根据你的意见:铁蓬没有藏书。 相反,<代码> 模块在C#中写,在铁蓬。 模块。 确保该项目也参考了你的项目和与铁Python.dll相同的目录。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签