Can anyone help me out what I did wrong. So i need to print out the name read from file in a column of list like this:
admin
admin
admin
....
admin
But my code keep printing out the name sideways like this:
['admin', 'admin', 'admin', 'admin', 'admin']
Any help would really appreciate.
# Define a function
def parse_file():
users = []
filename = "auth.log"
file = open(filename, 'r')
string = "invalid user"
# Parsing auth.log file, detect invalid users, sort them and return the result
for i in file:
i = i.lower()
pos = i.find(string)
if pos >= 0:
index = pos + len(string) + 1
user = i[index:].split(" ")[0]
users.append(user)
users.sort()
return users
if __name__ == "__main__":
print(parse_file( ))