Skip to content
Snippets Groups Projects
Commit ca0aa6d0 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add utils.ReadFile function

It abstracts exception handling and is like a complement to
utils.WriteFile.

Reviewed-by: iustinp
parent b5b22be2
No related branches found
No related tags found
No related merge requests found
......@@ -864,6 +864,23 @@ def NewUUID():
f.close()
def ReadFile(file_name, size=None):
"""Reads a file.
@type size: None or int
@param size: Read at most size bytes
"""
f = open(file_name, "r")
try:
if size is None:
return f.read()
else:
return f.read(size)
finally:
f.close()
def WriteFile(file_name, fn=None, data=None,
mode=None, uid=-1, gid=-1,
atime=None, mtime=None, close=True,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment