Can't use DateTime in IronPython

前端 未结 2 772
野的像风
野的像风 2021-01-02 17:33

I\'m hosting my IronPython in a C# webapp like so:

var engine = Python.CreateEngine();
var scope = engine.CreateSc         


        
相关标签:
2条回答
  • 2021-01-02 18:09

    Just checked, and the problem is that you're trying to call Today as a method instead of a property. Try this instead (no need to add a reference to System.Core):

    import clr
    from System import DateTime
    theDate = DateTime.Today
    print theDate
    
    0 讨论(0)
  • 2021-01-02 18:15

    Try adding a reference to mscorlib instead of System.Core. We changed the default hosting behavior at some point (2.0.1? 2.0.2?) so that this is done by default when hosting. You can do this from your hosting code with:

    engine.Runtime.LoadAssembly(typeof(string).Assembly);
    
    0 讨论(0)
提交回复
热议问题