12 if output_file
is None:
13 output_file = input_file
14 if not os.path.exists(os.path.dirname(os.path.realpath(output_file))):
15 os.makedirs(os.path.dirname(os.path.realpath(output_file)))
18 with open(
'tmp.txt',
'w')
as fw:
19 with open(input_file,
'r') as ftmp: 21 if re.search(
'\s*</event>', line):
23 fw.write(
'<event_num num="' +
str(nevent) +
'"> ' +
str(nevent) +
'</event_num>\n')
25 if output_file
is not None:
26 os.rename(
"tmp.txt", output_file)
28 os.rename(
"tmp.txt", input_file)
def number_events(input_file, output_file=None, offset=0)