0
如何使用python替換文件中的特定文本行。看看我們是否有一個叫做「File1.tcl」。併爲單詞「:: AgtQtl :: CloseAllOutputFiles」找到一個特定位置。如果發現替換爲下面的文字。可以ANY1幫我這...使用python替換文本文件中的特定行?
File1.tcl:
AgtQtl::SetupOutputFiles
if { [AddAllPorts] } {
set result [PreparePorts]
InitPortInfo
#
# start the test
#
if { [AgtQtl::GetScriptMode] != "COMMANDLINE" } {
::TestGui::ShowResult None black gray -noraise
}
GenerateReportSection HEADER
if { $result } {
if [AddSubinterfaces] {
RunTestLoop
} else {
set message [list "Add sub-interfaces" "FAIL"]
GenerateReportSection BODYRECORD $message
lappend statLog $message
}
} else {
set message [list "Prepare ports" "FAIL"]
GenerateReportSection BODYRECORD $message
lappend statLog $message
}
set appData(testStopTime) [clock seconds]
set testPassFailMsg [DeterminePassFail]
if { $testPassFailMsg == "" } {
set testPassFailMsg "PASSED"
}
set appData(testPassFailMsg) $testPassFailMsg
GenerateReportSection FOOTER
::TestApp::StopTest
}
}
AgtTsuTestState TEST_STOPPED
if { [AgtQtl::GetScriptMode] != "COMMANDLINE" } {
switch $testPassFailMsg {
PASSED {
set testPassFailMsg "PASS"
set fgColour black
set bgColour green
}
default {
set testPassFailMsg "FAIL"
set fgColour black
set bgColour red
}
}
::TestGui::ShowResult $testPassFailMsg $fgColour $bgColour
}
::AgtQtl::CloseAllOutputFiles
return $result
}
在此代碼...尋找這一行文字 「:: AgtQtl :: CloseAllOutputFiles」 的
如果發現..這個行代碼
set filelid [open "C:/Sanity_Automation/Work_Project/Output/smokeTestResult" w+]
puts $filelid
close $filelid