iLesen einer Textdatei für Schleife in Python mit verschachtelten
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
Aus dieser Datei eine Datei zuerst muss ich Konfiguration 1 lesen, dann unter, dass ich brauche, um Reed Pw1 und dann, dass unter ich muss lies die configurations.at time ich sollte bis Endkonfiguration lesen.
Nachdem die Konfigurationen i tun müssen, die die Konfiguration 2 und pw unter that.Can jemand mir helfen, mit dieser
Haben Sie etwas versucht? Bitte erwähnen Sie Ihren Code oder eine mögliche Lösung, an die Sie gedacht haben. Gehen Sie zu docs.python.org und sehen Sie, wie Sie eine Datei in Python lesen können, wenn Sie neu sind. – Shashank
Haben Sie das selbst versucht? Im Moment liest dies als * "Bitte schreiben Sie meinen Code für mich" * – SiHa
für pw_num im Bereich (int (testcase_dict ['Anzahl der Pw'])): ##### konfigurieren alle pw \t \t Num_PW = int (pw_num) + 1 \t \t \t \t test_file = open ("Section% sConfigurations.txt" % qvs_section 'r') \t \t test_lines = test_file.readlines() \t \t \t \t Ausfahrt \t \t PW = "PW" + str (Num_PW) \t \t EndPW = "EndPW" \t \t Temp = False \t \t für i in test_lines: \t \t \t \t \t wenn Testfall == i.strip(): \t \t \t \t \t \t \t \t für i in test_lines: \t \t \t \t \t \t \t \t \t \t \t \t \t \t wenn PW == i.Streifen(): \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t für i in test_lines: \t \t \t \t \t \t \t drucken i \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 wenn i == EndPW: \t \t \t \t \t \t \t \t Pause \t \t \t \t, wenn i == „EndConfiguration“: \t \t \t \t \t \t Pause –