读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中你好,
我创建了一个表,然后打开一个 zip 文件夹,首先将日志文件保存到特定路径,然后读取文件(长文本文件),然后检查它是否包含字符串。如果是,则向创建的表添加新行并添加值。一切正常,直到向表添加新行和值。 我无法弄清楚问题是什么,因为日志中没有错误或信息。 以下是我的脚本,有人可以提出建议是什么问题吗?
dt = open(sometable);
lst2 = column(dt1, "t1") << Get Values;
dt2 = new table("data_"||todaydate,
new column("t1", character),
newcolumn("data", character)
);
for (k=1, k <=N items(lst2), k++,
//print (lst2[k]);
Try(
za = open(path2||lst2[k], zip);
dirlist = za << dir;
//show(dirlist); //check the list
for (l=1, l<=N Items(dirlist), l++,
If (Left(dirlist[l],5) == "tests" & Right(dirlist[l],8) == "_raw.log" ,
show(dirlist[l]);
text = za << read(dirlist[l]);
//print (dirlist[l]);
save text file(path1|| Format Date( Today(), "ddmonyyyy" ) ||"\"||lst2[k]||"_"||dirlist[l],text);
,
dirlist[l]== "line.log" ,
text = za << read(dirlist[l]);
if(contains(text, "string"),
dt2 << add rows (t1 = lst2[k], data = "Yes"),
dt2 << add rows (t1 = lst2[k], data = "No")
);
);
)
,
print (lst2[k] || "fail to open");
Throw();
);
);
自动化和脚本编写回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中我想我发现了问题。 需要 {} 。 之前没有 {} 也能正常工作。 有人知道为什么现在需要 {} 吗?
dt2 << add rows ({t1 = lst2[k], data = "Yes"}),
dt2 << add rows ({t1 = lst2[k], data = "No"})
回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中
Help->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting IndexHelp->Scripting Index帮助->脚本索引
至少从 JMP 14 开始,文档就一直这样。 您是否发现版本之间的行为发生了变化?
回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中嗨克雷格,
我在下面做的事情并成功,仅将行和值添加到其中一列。
dt2 = new table("data_"||todaydate,
new column("t1", character),
newcolumn("data", character)
);
for (k=1, k <=N items(lst2), k++,
dt2 << add rows (t1 = lst2[k])
);
回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中如果 lst2[k] 是一个数字,也许是 1,我可以看到它是如何工作的。 将评估分配,更改(旧)当前行的 t1,然后结果(在 t1 中)将是要添加的行数。但是这些行直到下一次循环才会被分配值。 但这不太适合你所拥有的(角色 t1),所以也许不适合。
很高兴你已经弄清楚了;该列表不会评估列表中的项目。 相反,该列表被传递到 add rows 方法中,并且 addrows 使用新添加的行上的列表。
回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中在上面的原始脚本中,我有一个关于 try() 和 throw() 的以下问题。 我遇到一种情况,try() + throw() 不跳过并继续循环中的下一个。 问题发生在读取 line.log 时。 其中一个line.log太大,无法打开。 我得出这样的结论是因为我尝试手动打开特定的 line.log ,但它给了我一个错误,说文件太大而无法通过 txt 打开。 因此添加了另一个 try() 和 throw() ,但它仍然只打印了 lst2[k]"cannot read" 和 lst2[k[ "fail to open" 的消息。然后循环停在 lst2[k] 处,不会进入下一个循环。 我在如何使用 try() 和 throw() 方面犯了错误吗?
dt = open(sometable);
lst2 = column(dt1, "t1") << Get Values;
dt2 = new table("data_"||todaydate,
new column("t1", character),
newcolumn("data", character)
);
for (k=1, k <=N items(lst2), k++,
//print (lst2[k]);
Try(
za = open(path2||lst2[k], zip);
dirlist = za << dir;
//show(dirlist); //check the list
for (l=1, l<=N Items(dirlist), l++,
If (Left(dirlist[l],5) == "tests" & Right(dirlist[l],8) == "_raw.log" ,
show(dirlist[l]);
text = za << read(dirlist[l]);
//print (dirlist[l]);
save text file(path1|| Format Date( Today(), "ddmonyyyy" ) ||"\"||lst2[k]||"_"||dirlist[l],text);
,
dirlist[l]== "line.log" ,<BR />try(
text = za << read(dirlist[l]);
if(contains(text, "string"),
dt2 << add rows (t1 = lst2[k], data = "Yes"),
dt2 << add rows (t1 = lst2[k], data = "No")
);<BR />,<BR />print(lst2[k] || "cannot read");<BR />throw();<BR />);
);
)
,
print (lst2[k] || "fail to open");
Throw();
);
);回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中我重新格式化了代码(control-M)来查看结构,我认为你想省略 throw()
The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,The error from <<read was caught, then re-thrown to the outer try,来自 <
您可能也不想要外部投掷。 有时像这样使用 throw() 是可取的,如果你真的意味着你还没有完成处理异常并希望它传播到包含处理程序,但至少对于内部尝试,我认为你已经处理好它并希望循环继续。
回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中仅删除内部 throw() 脚本输出所有 lst2[k] “无法读取”。 但是,如果删除内部和外部 throw(),脚本将按设计运行。
回复:读取 zip 文件,如果包含“字符串”,则将行添加到带有值标签的表中我想你已经有了答案,只是为了澄清一下:
dt = Open( sometable );
lst2 = Column( dt1, "t1" ) << Get Values;
dt2 = New Table( "data_" || todaydate, New Column( "t1", character ), New Column( "data", character ) );
For( k = 1, k <= N Items( lst2 ), k++,
Try(
za = Open( path2 || lst2[k], zip );
dirlist = za << dir;
For( l = 1, l <= N Items( dirlist ), l++,
If( Left( dirlist[l], 5 ) == "tests" & Right( dirlist[l], 8 ) == "_raw.log",
Show( dirlist[l] );
text = za << read( dirlist[l] );
Save Text File( path1 || Format Date( Today(), "ddmonyyyy" ) || "\" || lst2[k] || "_" || dirlist[l], text );
,/*else if*/ dirlist[l] == "line.log",
Try(
text = za << read( dirlist[l] );
If( Contains( text, "string" ),
dt2 << add rows( t1 = lst2[k], data = "Yes" ),
dt2 << add rows( t1 = lst2[k], data = "No" )
);
,/* catch*/
Print( lst2[k] || "cannot read" );
Throw(); // this throw will end the for-L loop
);
);
);
,/*catch*/
Print( lst2[k] || "fail to open" );
Throw(); // this throw will end the for-K loop
)
);