answered 14 years ago
with open("outputfilepath", 'w') as fp: for line in iterable: #assuming line is str with \n print >> fp, line #implicit fp.close() here as "with" scope ends.