mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge bitcoin/bitcoin#24993: test, contrib, refactor: use with when opening a file
027aab663atest, contrib, refactor: use `with` when opening a file (brunoerg) Pull request description: When manipulating a file in Python without using `with()`, you have to close the file manually, so this PR does it in `get_block_hashes` (`contrib/linearize/linearize-data.py`). Edit: this PR does it for all occurances that previously weren't using `with`. ACKs for top commit: laanwj: Code review ACK027aab663aTree-SHA512: 879400968e0013e8678ec16f1fe5d0963a73c1e0d442ca34802d885214f0783d2e9a9b500fc6be7c3b93560a367b6a3d685eee24d2f9ce53fddf064ea6feecf8
This commit is contained in:
@@ -320,15 +320,13 @@ def get_most_recent_git_change_year(filename):
|
||||
################################################################################
|
||||
|
||||
def read_file_lines(filename):
|
||||
f = open(filename, 'r', encoding="utf8")
|
||||
file_lines = f.readlines()
|
||||
f.close()
|
||||
with open(filename, 'r', encoding="utf8") as f:
|
||||
file_lines = f.readlines()
|
||||
return file_lines
|
||||
|
||||
def write_file_lines(filename, file_lines):
|
||||
f = open(filename, 'w', encoding="utf8")
|
||||
f.write(''.join(file_lines))
|
||||
f.close()
|
||||
with open(filename, 'w', encoding="utf8") as f:
|
||||
f.write(''.join(file_lines))
|
||||
|
||||
################################################################################
|
||||
# update header years execution
|
||||
|
||||
Reference in New Issue
Block a user