Я пытаюсь запустить следующий код:Не может оценить строковое выражение списка в список в Python (индексы списка должны быть целыми или дольки, а не кортеж - ошибка)
file = open("Modern Text List", "r").read()
print(file)
print(eval(file))
Чтобы изменить этот текст :
[['List Of Modern Text'], ['Speaker', 'Dialogue'], ['FIRST WITCH', 'When should the three of us meet again? Will it be in thunder,
lightning, or rain?']][['List Of Modern Text'], ['Speaker', 'Dialogue'], ['FIRST WITCH', 'When should the three of us meet again? Will it be in thunder, lightning, or rain?']][['List Of Modern Text'], ['Speaker', 'Dialogue'], ['FIRST WITCH', 'When should the three of us meet again? Will it be in thunder, lightning, or rain?']][['List Of Modern Text'], ['Speaker', 'Dialogue'], ['FIRST WITCH', 'When should the three of us meet again? Will it be in thunder,
lightning, or rain?']]
в список python.
Но я получаю эту ошибку:
<ipython-input-46-695cb87082c4> in <module>()
14 print(type(file))
15
---> 16 print(eval(file))
<string> in <module>()
TypeError: list indices must be integers or slices, not tuple
В моей JupyterNotebook.
Код был выполнен вчера. Кажется, сегодня не работает.
Я новичок в этом, поэтому, пожалуйста, объясните, как это решить. Спасибо!
не отвечайте на свой вопрос использовать редактирование – Frogboxe
@Frogboxe, отвечая на ваш собственный вопрос [явно поощряется] (http://stackoverflow.com/help/self-answer) здесь - редактирование ответа на вопрос точно * неправильный подход. –
Ой, я не знаю, откуда у меня эта идея. Неважно, что я сказал тогда. – Frogboxe