Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure citations file closed after read #1620

Merged
merged 4 commits into from
Aug 26, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions pybamm/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ def read_citations(self):
citation = ""
start = True

for line in open(citations_file):
# if start is true, we need to find the key
if start is True:
# match everything between { and , in the first line to get the key
brace_idx = line.find("{")
comma_idx = line.find(",")
key = line[brace_idx + 1 : comma_idx]
# turn off start as we now have the right key
start = False
citation += line
# blank line means next block, add citation to dictionary and
# reset everything
if line == "\n":
self._all_citations[key] = citation
citation = ""
start = True

# add the final citation
self._all_citations[key] = citation
with open(citations_file) as f:
for line in f:
# if start is true, we need to find the key
if start is True:
# match everything between { and , in the first line to get the key
brace_idx = line.find("{")
comma_idx = line.find(",")
key = line[brace_idx + 1 : comma_idx]
# turn off start as we now have the right key
start = False
citation += line
# blank line means next block, add citation to dictionary and
# reset everything
if line == "\n":
self._all_citations[key] = citation
citation = ""
start = True

# add the final citation
self._all_citations[key] = citation

def register(self, key):
"""Register a paper to be cited. The intended use is that :meth:`register`
Expand Down