Найти - Пользователи
Полная версия: Ошибка в цикле for ... in enumerate:
Начало » Python для новичков » Ошибка в цикле for ... in enumerate:
1
ghostly_dog
Выходит ошибка:
“Traceback (most recent call last):
File ”C:/py3/listkeeper.py“, line 63, in <module>
main()
File ”C:/py3/listkeeper.py“, line 4, in main
fh = choise_file()
File ”C:/py3/listkeeper.py“, line 29, in choise_file
print(”{1}: {2} file".format(lino, list))
IndexError: tuple index out of range"

Код представлен не в полном объеме, т.к. там только шаблон набросан
def main():
fh = choise_file()
if len(fh) == 0:
print("No items are in the list")
else:
for lino, line in enumerate(fh, start=1):
print("{1}. {2}".format(lino, line))
choise_func()
return

def choise_file():
fh = None
lists_all = []
lists_lst = []
lists_all = os.listdir(".")
for list in lists_all:
if list.endswith((".lst")):
lists_lst.append(list)
if len(lists_lst) == 0:
list = input("Enter name file:")
list += ".lst"
lists_lst.append(list)
fh = open(list, "w", encoding="utf8")
else:
for lino, list in enumerate(lists_lst, start=1):
print("{1}: {2} file".format(lino, list))
num_file = input("Enter number file: ")
fh = open(lists_lst[num_file-1], "w", encoding="utf8")
return fh

main()
bazooka
>>> print("{0}: {1} file".format('omg', 'wtf'))
omg: wtf file
>>> print("{1}: {2} file".format('omg', 'wtf'))

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
print("{1}: {2} file".format('omg', 'wtf'))
IndexError: tuple index out of range
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB