mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-10 10:19:10 -07:00
use open() as context manager (#9579)
* use open() as context manager * add changelog frag
This commit is contained in:
parent
c5cc949492
commit
0de39a6f47
13 changed files with 72 additions and 102 deletions
|
@ -588,11 +588,8 @@ def read_record(file_path, default=None):
|
|||
Reads the first line of a file and returns it.
|
||||
"""
|
||||
try:
|
||||
f = open(file_path, 'r')
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
return f.readline().strip()
|
||||
finally:
|
||||
f.close()
|
||||
except IOError:
|
||||
return default
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue