0

Weird index error python

I'm creating a program that iterates through a text file and, starting at the beginning of a specific set of user credentials(of which i call "Cases"), and appropriately puts the username and password characters (in hexadecimal) into appropriate username and password arrays. although, however small, i'm getting a silly index error when iterating through the array. have i fallen off the array at the end? someone, please tell me what i'm doing wrong. here's the code: https://code.sololearn.com/chKP2oR0Fcfc This is what the notepad should look like: ------------------CASE 0: 0x4e 0x61 0x73 0x69 0x72 0x20 0x4d 0x75 0x68 0x61 0x6d 0x6d 0x61 0x64 UPASSWORD: 0x31 0x32 0x33 0x34 0x35 --END-- ------------------CASE 1: 0x4a 0x6f 0x68 0x6e 0x20 0x73 0x6d 0x69 0x74 0x68 UPASSWORD: 0x61 0x62 0x63 0x64 0x65 --END-- ------------------CASE 2: 0x6e 0x64 0x72 0x61 0x20 0x44 0x6f 0x72 0x6f 0x74 0x68 0x79 UPASSWORD: 0x78 0x79 0x7a ==END==

4th Dec 2017, 5:54 PM
X-1
X-1 - avatar
1 Resposta
+ 1
Hi, it is quite clear that you get the index error because of this line: while credsArr[c2Line] != "--END--" or credsArr[c2Line] != "==END==": Think about the condition, this will be always true so the code reaches the end of your .txt file and is out of index. Try this: while credsArr[c2Line] != "--END--" and credsArr[c2Line] != "==END==": Let me know if this is what you were looking for. Filip
5th Dec 2017, 10:03 PM
FilipCZ
FilipCZ - avatar