如何使用 python 替换文件中的特定文本行。看看我们是否有一个名为“File1.tcl”。并找到一个特定的单词“::AgtQtl::CloseAllOutputFiles”。如果找到替换为以下文本。任何人都可以帮我解决这个问题...
文件1.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