2010-05-17 7 views

cevap

16

Ayrıca yapabilirsiniz:

Python 2.7 ve içinde
from contextlib import nested 

with nested(open(spam), open(eggs)) as (f_spam, f_eggs): 
    # do something 

3.1+ with aşağıdaki sözdizimini destekler çünkü nested işlevini gerekmez: u yapacağını nasıl

with open(spam) as f_spam, open(eggs) as f_eggs: 
    # do something 
+0

Python 3'te mi? – Tshepang

+3

'f_spam olarak açık (spam) ile f_eggs olarak açın (yumurta):' .................. http: // docs adresindeki dördüncü madde işaretine bakın. python.org/release/3.1/whatsnew/3.1.html#other-language-changes – blokeley

3
with open(spam,'r') as f_spam: 
    with open(eggs,'r') as f_bar: 
    #do stuff with each 
İlgili konular