fn = raw_input("Enter file to open: ")
fileObject = open(fn,'r+')
dictionary = {}
for line in fileObject:
x = line.split(":")
a = x[0]
b = x[1]
c = len(b)-1
b = b[0:c]
dictionary[a] = b
print dictionary
After I tested my program, I found out everything were perfect except for 2 tiny issues. Can you please tell me what is wrong?
My text file has the following in it:
username1:password1
username2:password2
username3:password3
username4:password4
username5:password5
(This is an empty line in the actual text file)
First problem: My program reads the file into a dictionary perfectly but it is reading out of order, i tried to print the dictionary after the reading into the dictionary part and below is what I got.
{'username1': 'password1', 'username3': 'password3', 'username2': 'password2', 'username5': 'password5', 'username4': 'password4'}
Second problem:
for the text file, after password5, I have to hit enter and save the text file to get this:
{'username1': 'password1', 'username3': 'password3', 'username2': 'password2', 'username5': 'passwor**d5'**, 'username4': 'password4'}
if I don't hit enter at the end of the text file, then it will become this:
{'username1': 'password1', 'username3': 'password3', 'username2': 'password2', 'username5': 'passwo**rd'**, 'username4': 'password4'}