From e3ad11a6a057c4a73618ac62cab045b086f28d6c Mon Sep 17 00:00:00 2001 From: KV Date: Tue, 21 Jul 2020 22:26:21 +0200 Subject: [PATCH] Move open_file_append() outside the if to avoid re-open --- src/wireviz/build_examples.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wireviz/build_examples.py b/src/wireviz/build_examples.py index d6eb990a..73cb861e 100755 --- a/src/wireviz/build_examples.py +++ b/src/wireviz/build_examples.py @@ -52,17 +52,15 @@ def build(dirname, build_readme, include_source, include_readme): if build_readme: i = ''.join(filter(str.isdigit, yaml_file.stem)) - if include_readme: - with open_file_append(path / readme) as out: + with open_file_append(path / readme) as out: + if include_readme: with open_file_read(path / f'{yaml_file.stem}.md') as info: for line in info: out.write(line.replace('## ', '## {} - '.format(i))) out.write('\n\n') - else: - with open_file_append(path / readme) as out: + else: out.write(f'## Example {i}\n') - with open_file_append(path / readme) as out: if include_source: with open_file_read(yaml_file) as src: out.write('```yaml\n')