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