Skip to content

Commit

Permalink
bob.measure.open_file now accepts file-like objects (which are direct…
Browse files Browse the repository at this point in the history
…ly returned).
  • Loading branch information
Manuel Guenther committed Jan 7, 2015
1 parent fbf004c commit 89fbc73
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bob/measure/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ def open_file(filename):
Score files might be raw text files, or a tar-file including a single score file inside.
Parameters:
filename The name of the score file to open. This file might be a raw text file or a (compressed) tar file containing a raw text file.
filename : str or file-like
The name of the score file to open, or a file-like object open for reading.
If a file name is given, the according file might be a raw text file or a (compressed) tar file containing a raw text file.
Returns:
A read-only file-like object as it would be returned by open().
"""
if not isinstance(filename, str) and hasattr(filename, 'read'):
# It seems that this is an open file
return filename

if not os.path.isfile(filename):
raise IOError("Score file '%s' does not exist." % filename)
if not tarfile.is_tarfile(filename):
Expand Down

0 comments on commit 89fbc73

Please sign in to comment.