(我正在使用OpenXML SDK与IronPython中的WordprocessingDocument对象进行交互式工作,但这实际上是一个普遍的Python问题,应该适用于所有实现)
我试图从一些Word文档中删除一些表.对于每个表,我有一个给我表行对象的迭代器.然后,我使用以下生成器语句从每行获取单元格元组:
for row in rows:
t = tuple([c.InnerText for c in row.Descendants[TableCell]()])
Run Code Online (Sandbox Code Playgroud)
每个元组包含4个元素.现在,在t[1]每个元组的列中,我需要对数据应用正则表达式.我知道元组是不可变的,所以我很高兴要么创建一个新的元组,要么以不同的方式构建元组.鉴于row.Descendants[TableCell]()返回迭代器,从迭代器构造元组的最Pythonic(或至少最简单)方法是什么,我想修改n返回的元素?
我现在的暴力方法是从左切片(t[:n-1]),修改后的数据t[n]和右切片(t[n+1:])创建一个元组,但我觉得itertools模块应该有一些东西可以帮助我在这里.
我希望在ironpython中加载.net dll.
但是.net dll中的一个静态函数有一些Named和Optional Arguments.
比如,画(重量:w,高度:h,面积= 1)
我只能使用完整的参数吗?
我按照这里的最佳答案示例到T,用Pyc.py进行编译.
我得到一个例外 pyScope = pyEngine.ImportModule("MyClass");
no module named MyClass
Run Code Online (Sandbox Code Playgroud)
我相信这是一个错误,因为有时使用Pyc.py进行重新编译会生成一个dll ImportModule识别,但有时它不会.
结论:如下面通过digEmAll所述,以这种方式使用Pyc.py编译模块会产生随机结果.而是手动调用clr.CompileModules.
我有以下C#代码将其编译为MyMath.dll程序集.
namespace MyMath {
public class Arith {
public Arith() {}
public int Add(int x, int y) {
return x + y;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下IronPython代码来使用此对象.
import clr
clr.AddReferenceToFile("MyMath.dll")
import MyMath
arith = Arith()
print arith.Add(10,20)
Run Code Online (Sandbox Code Playgroud)
当我使用IronPython运行此代码时,我收到以下错误.
Traceback (most recent call last): File ipycallcs, line unknown, in Initialize NameError: name 'Arith' is not defined
可能有什么问题?
arith = Arith()应该是arith = MyMath.Arith()
我正在尝试将WPF工具包与我的Visual 2010项目一起使用(我对System.Windows.Controls.DataVisualization命名空间中的图表控件感兴趣),但无法确定要引用的程序集.
我已经安装了工具包,它似乎已安装到C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1.我已经阅读了一些关于如何将程序集复制到GAC的帖子,但我尝试了以下代码:
import clr
clr.AddReference("WPFToolkit")
Run Code Online (Sandbox Code Playgroud)
仍然失败.
有人在VS2010最近使用过WPF Toolkit吗?你是如何添加引用的呢?
我已经通过NuGet将IronPython标准库添加到我的c#.net4项目中,后来得到了一些参考资料(IronPython,IronPython.Modules,IronPython.SQLite,IronPython.Wpf,Microsoft.Dynamic,Microsoft.Scripting等)和'Lib'文件夹包含python模块.现在我试图在我的file.py中导入'urllib'模块但是接收ImportException(没有名为urllib的模块).我怎么用urllib?我应该将Lib文件夹复制到项目输出目录还是做其他事情?
UPD:如果我将所需的模块复制到项目输出目录,那么程序无需设置路径即可正常工作.我可以使用'urllib'作为嵌入式资源或在运行时导入它吗?
谢谢!
资料来源:
public static void Main(string[] args)
{
var url = new Uri("www.microsoft.com");
var r = PythonHelper.Get(url);
}
public static class PythonHelper
{
public static string Get(Uri url)
{
var programPath = @"PySources\GetPage.py";
var py = new Py(programPath);
py.Scope.SetVariable("url", url.ToString());
py.Source.Execute();
var result = py.Scope.GetVariable<string>("result");
return result;
}
private class Py
{
public ScriptScope Scope { get; private set; }
public ScriptSource Source { get; private set; }
public Py(string pyPath)
{
var pyEngine = Python.CreateEngine();
Scope …Run Code Online (Sandbox Code Playgroud) 我试图获得曲线的长度,但我收到的消息:MissingMemberException: 'Guid' object has no attribute 'length'C#中的相同脚本完美无缺.python翻译有什么问题?这是文档.
蟒蛇:
import rhinoscriptsyntax as rs
ln = rs.AddLine(pt1, pt2)
a = ln
b = ln.Length
Run Code Online (Sandbox Code Playgroud)
C#:
Line ln;
ln = new Line(pt1, pt2);
A = ln;
B = ln.Length;
Run Code Online (Sandbox Code Playgroud) 这似乎只是一个我无法弄清楚的简单错误.我在C#WPF应用程序中使用IronPython,并在尝试从自定义C#类运行函数时收到以下错误:AttributeError: 'MyScriptingFunctions' object has no attribute 'Procedure'.
我正在运行的python脚本非常简单,有两行.第1行执行正常,错误发生在第2行.
txt.Text = "some text"
MyFunc.Procedure(5)
Run Code Online (Sandbox Code Playgroud)
MyScriptingFunctions.cs:
class MyScriptingFunctions
{
public MyScriptingFunctions() {}
public void Procedure(int num)
{
Console.WriteLine("Executing procedure " + num);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我设置IronPython引擎的方法:
private void btnRunScript_Click(object sender, RoutedEventArgs e)
{
MyScriptingFunctions scriptFuncs = new MyScriptingFunctions();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ScriptRuntime runtime = engine.Runtime;
runtime.LoadAssembly(typeof(String).Assembly);
runtime.LoadAssembly(typeof(Uri).Assembly);
//Set Variable for the python script to use
scope.SetVariable("txt", fullReadResultsTextBox);
scope.SetVariable("MyFunc", scriptFuncs);
string code = this.scriptTextBox.Text;
try
{
ScriptSource …Run Code Online (Sandbox Code Playgroud) 我有一个csv字符串输入
string_in="country,100,color"
任何人都可以建议我如何
使用spotfire中的ironpython脚本将此输入(string_in)附加到已存在的数据表可视化.
谢谢.
可以请一个人提供python脚本来创建多个选择列表框过滤器(带有搜索选项)。当我单击嵌入脚本的按钮时,应该对仪表板页面中存在的所有四个数据表的数据进行过滤。
我已经编写了一些脚本,但是如果仅存在一个数据表,它将可以正常工作,当我尝试对多个数据表中的数据应用过滤器时,我遇到了一些错误。
from Spotfire.Dxp.Applica??tion
import Filters as filters
CurPanel = Document.ActivePageR??eference.FilterPanel
FilterA = CurPanel.TableGroups??[0].GetFilter("column??name")
CheckBoxes = FilterA.FilterRefere??nce.As[filters.CheckB??oxFilter]()
strCityL = Document.Properties[??"propertyname"]
for CheckBoxVal in CheckBoxes.Values:
CheckBoxes.Uncheck(C??heckBoxVal)
for strVal in strCityL:
CheckBoxes.Check(st??rVal)
Run Code Online (Sandbox Code Playgroud)
上面的脚本用于一个数据表,我无法搜索过滤器值
谢谢
ironpython ×10
.net ×4
c# ×4
python ×4
spotfire ×2
generator ×1
grasshopper ×1
iterator ×1
rhino3d ×1
wpf ×1
wpftoolkit ×1