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: | file : filepath, url, filehandle, list
mode : {‘r’, ‘w’}, optional
encoding : str, optional
errors : str, optional
newline : {None, “”, ‘\n’, ‘\r\n’, ‘\r’}, optional
compression : {‘auto’, ‘gzip’, ‘bz2’, None}, optional
compresslevel : int (0-9 inclusive), optional
|
---|---|
Returns: | filehandle : io.TextIOBase or io.BufferedReader/Writer
|