Если вы используете python 2.7, я считаю, что вам нужно использовать raw_input()
в Python 3.X правильно использовать input()
. Кроме того, вы неправильно используете append()
, метод добавления списков - Добавить.
fname = raw_input("Enter filename: ") # Stores the filename given by the user input
fh = open(fname,"r") # Here we are adding 'r' as the file is opened as read mode
lines = fh.readlines() # This will create a list of the lines from the file
# Sort the lines alphabetically
lines.sort()
# Rstrip each line of the lines liss
y = [l.rstrip() for l in lines]
# Print out the result
print y
Пожалуйста, дайте мне знать, помогло ли это вам. Спасибо!