我正在尝试将以下构造 IronPython 模块的 C# 示例转换为 F#。
using System;
using IronPython.Runtime;
[assembly: PythonModule("my_module", typeof(MyModule))]
public static class MyModule {
public static void hello_world() {
Console.WriteLine("hello world");
}
}
使用 PythonModule 允许 from my_module import *
,等等。
我无法弄清楚如何在 F# 中应用 PythonModule 属性。 F# 文档只讨论与模块相关的程序集属性,并附在 do() 上。我不清楚如何定义被解释为 python 模块的静态类,但我不是 C#/F#/IronPython 专家。
最佳答案
我手头没有所有的东西来查看这是否有效,但我会尝试
open System
open IronPython.Runtime
type MyModule =
static member hello_world() =
Console.WriteLine("hello world")
module DummyModuleOnWhichToAttachAssemblyAttribute =
[<assembly: PythonModule("my_module", typeof<MyModule>)>]
do ()
初学者。
关于c# - 在 F# 中使用程序集属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2269625/