讀取 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,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
)
);