<s> """<STR_LIT>""" <EOL> import csv <EOL> def get_line ( f , strip_comments = False ) : <EOL> line = f . readline ( ) <EOL> if strip_comments : <EOL> line = line . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . rstrip ( ) <EOL> return line <EOL> def seek ( f , line_content , strip_comments = False ) : <EOL> line = get_line ( f , strip_comments ) <EOL> while line . strip ( ) != line_content : <EOL> line = get_line ( f , strip_comments ) <EOL> return line <EOL> def leading_spaces ( line ) : <EOL> return len ( line ) - len ( line . lstrip ( '<STR_LIT:U+0020>' ) ) <EOL> def get_block ( filename , block ) : <EOL> with open ( filename , '<STR_LIT:r>' ) as f : <EOL> line = seek ( f , block , strip_comments = True ) <EOL> spaces = leading_spaces ( line ) <EOL> lines = [ ] <EOL> while True : <EOL> line = f . readline ( ) <EOL> if not line or leading_spaces ( line ) == spaces : <EOL> break <EOL> lines . append ( line [ spaces + <NUM_LIT:4> : ] ) <EOL> return '<STR_LIT>' . join ( lines ) <EOL> def get_section ( f , outside_indentation ) : <EOL> collector = [ ] <EOL> while True : <EOL> line = f . readline ( ) <EOL> if leading_spaces ( line ) == outside_indentation : <EOL> break <EOL> setting , line = line . split ( '<STR_LIT::>' , maxsplit = <NUM_LIT:1> ) <EOL> try : <EOL> default , comment = line . split ( '<STR_LIT:#>' , maxsplit = <NUM_LIT:1> ) <EOL> except ValueError : <EOL> default = line <EOL> comment = '<STR_LIT>' <EOL> line_tuple = ( setting . strip ( ) , default . strip ( ) , comment . strip ( ) ) <EOL> if not line_tuple [ <NUM_LIT:2> ] . startswith ( '<STR_LIT>' ) : <EOL> collector . append ( line_tuple ) <EOL> return collector , line <EOL> def write_csv ( filename , iterable ) : <EOL> with open ( filename , '<STR_LIT:w>' , newline = '<STR_LIT>' ) as f : <EOL> writer = csv . writer ( f ) <EOL> writer . writerows ( iterable ) <EOL> def process ( ) : <EOL> filename = '<STR_LIT>' <EOL> with open ( filename , '<STR_LIT:r>' ) as f : <EOL> line = seek ( f , '<STR_LIT>' ) <EOL> line = f . readline ( ) <EOL> assert line . strip ( ) == '<STR_LIT>' <EOL> line = seek ( f , '<STR_LIT>' ) <EOL> constraints , line = get_section ( f , <NUM_LIT:8> ) <EOL> assert line . startswith ( '<STR_LIT>' ) <EOL> line = get_line ( f ) <EOL> costs , line = get_section ( f , <NUM_LIT:8> ) <EOL> write_csv ( '<STR_LIT>' , constraints ) <EOL> write_csv ( '<STR_LIT>' , costs ) <EOL> depreciation = get_block ( filename , '<STR_LIT>' ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( depreciation ) <EOL> for tech in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] : <EOL> block = get_block ( filename , tech + '<STR_LIT::>' ) <EOL> with open ( '<STR_LIT>' . format ( tech ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( block ) <EOL> process ( ) </s>
