On 22/01/2012 16:17, Yigit Turgut wrote:
[snip]
On Jan 22, 5:39 pm, Arnaud Delobelle<arno...@gmail.com>  wrote:
[snip]
 Or more succintly (but not tested):

 sections = [
     ("3", "section_1")
     ("5", "section_2")
     ("\xFF", "section_3")
 ]

 with open(input_path) as input_file:
     lines = iter(input_file)
     for end, path in sections:
         with open(path, "w") as output_file:
             for line in lines:
                 if line>= end:
                     break
                 output_file.write(line)

 --
 Arnaud

Good idea. Especially when dealing with variable numbers of sections.
But somehow  I got ;

     ("5", "section_2")
TypeError: 'tuple' object is not callable

That's due to missing commas:

sections = [
    ("3", "section_1"),
    ("5", "section_2"),
    ("\xFF", "section_3")
]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to