with open('f') as f:
with open('g') as g:
with open('h') as h:
pass
Начиная с Python 2.7 и 3.1, вы можете использовать всего один with:
o = open
with o('f') as f, o('g') as g, o('h') as h:
pass
До этого вы могли бы использовать функцию nested из contextlib:
from contextlib import nested
with nested(o('f'), o('g'), o('h')) as (f, g, h):
pass