-1
我有一个文件阅读使用嵌套for循环的文本文件在python
section2
Number of configurations:2
Configuration1
Number Of Pw:1
PW1
Frame_Type: E1 Unframed
Line_Code: AMI
Psn_Type:UDP/IPv4
Pw_Type: SAToP
Oam_Status: Enable
Prevent_PW_Broadcast: Enable
Multiplexing_Mode: Source
Out_Label: 1
In_Label: 8190
Payload_Size_Bytes: 128
Jitter_Buffer_Size: 10000
VLAN Tagging:Enable
VLAN ID:100
VLAN PRIORITY:1
file_name: MITOPExTx.img
server_ip: 192.168.205.23
software_version: 4.0(0.5)
EndPW
EndConfiguration
Configuration2
PW1
Frame_Type: E1 Unframed
Line_Code: AMI
Psn_Type: MEF
Pw_Type: SAToP
Oam_Status: Disable
Prevent_PW_Broadcast: Disable
Multiplexing_Mode: Destination
Out_Label: 16
In_Label: 1
Payload_Size_Bytes: 40
Jitter_Buffer_Size: 20000
EndPW
EndConfiguration
从该文件中的第一我需要读取配置1,则下,我需要芦苇PW1和然后下,我需要阅读配置。我应该阅读,直到完成配置。
做配置完成后我需要阅读下that.Can有人配置2和PW帮我这个
你尝试过什么吗?请提及您的代码或您想到的可能的解决方案。转到docs.python.org,看看如何在Python中读取文件。 – Shashank
你自己尝试过吗?目前,它的内容如下:*“请为我写代码”* – SiHa
pw_num在范围内(int(testcase_dict ['Number of Pw'])):#####配置所有pw \t \t Num_PW = INT(pw_num)+ 1个\t \t \t \t test_file里面=打开( “第%sConfigurations.txt” %qvs_section, 'R') \t \t test_lines = test_file.readlines()\t \t \t 出口\t \t \t PW = “PW”+ str(Num_PW) \t \t EndPW =“EndPW” \t \t温度=假 \t \t对于i在test_lines:\t \t \t \t \t如果测试用例== i.strip():\t \t \t \t \t \t \t \t对于i在test_lines:\t \t \t \t \t \t \t \t \t \t \t \t \t \t if PW == i。条():\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t对于i在test_lines: \t \t \t \t \t \t \t打印我\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t如果我== EndPW: \t \t \t \t \t \t \t \t休息 \t \t \t \t如果我==“EndConfiguration”: \t \t \t \t \t \t休息 –