Представьте, у меня есть такой код:
Код: Выделить всё
with open('file_1.txt', 'w') as file_1, \
open('file_2.txt', 'w') as file_2:
do_something()
Я пробовал:
Код: Выделить всё
with open('file_1.txt', 'w') as file_1, \
open('file_2.txt', 'w') as file_2 if my_condition:
do_something()
Подробнее здесь: https://stackoverflow.com/questions/793 ... -statement
Мобильная версия