skbio.io.util.
open
(file, mode='r', encoding=None, errors=None, newline=None, compression='auto', compresslevel=9)[source]¶Convert input into a filehandle.
State: Stable as of 0.4.0.
Supported inputs:
type | can read | can write | source type |
---|---|---|---|
file path | True | True | Binary |
URL | True | False | Binary |
["lines list\n"] |
True | True | Text |
io.StringIO |
True | True | Text |
io.BytesIO |
True | True | Binary |
io.TextIOWrapper |
True | True | Text |
io.BufferedReader |
True | False | Binary |
io.BufferedWriter |
False | True | Binary |
io.BufferedRandom |
True | True | Binary |
tempfile.TemporaryFile() |
True | True | Binary |
tempfile.NamedTemporaryFile() |
True | True | Binary |
Note
When reading a list of unicode (str) lines, the input for
newline is used to determine the number of lines in the resulting file
handle, not the number of elements in the list. This is to allow
composition with file.readlines()
.
Parameters: |
|
---|---|
Returns: | filehandle – When encoding=’binary’ an Note Any underlying resources needed to create filehandle are managed transparently. If file was closeable, garbage collection of filehandle will not close file. Calling close on filehandle will close file. Conversely calling close on file will cause filehandle to reflect a closed state. This does not mean that a `flush` has occured for `filehandle`, there may still have been data in its buffer! Additionally, resources may not have been cleaned up properly, so ALWAYS call `close` on `filehandle` and NOT on `file`. |
Return type: | io.TextIOBase or io.BufferedReader/Writer |