MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / open

Method open

functional/streams.py:76–121  ·  view source on GitHub ↗

Reads and parses input files as defined. If delimiter is not None, then the file is read in bulk then split on it. If it is None (the default), then the file is parsed as sequence of lines. The rest of the options are passed directly to builtins.open with the except

(
        self,
        path,
        delimiter=None,
        mode="r",
        buffering=-1,
        encoding=None,
        errors=None,
        newline=None,
    )

Source from the content-addressed store, hash-verified

74 return Sequence(args[0], engine=engine, max_repr_items=self.max_repr_items)
75
76 def open(
77 self,
78 path,
79 delimiter=None,
80 mode="r",
81 buffering=-1,
82 encoding=None,
83 errors=None,
84 newline=None,
85 ):
86 """
87 Reads and parses input files as defined.
88
89 If delimiter is not None, then the file is read in bulk then split on it. If it is None
90 (the default), then the file is parsed as sequence of lines. The rest of the options are
91 passed directly to builtins.open with the exception that write/append file modes is not
92 allowed.
93
94 >>> seq.open('examples/gear_list.txt').take(1)
95 [u'tent\\n']
96
97 :param path: path to file
98 :param delimiter: delimiter to split joined text on. if None, defaults to per line split
99 :param mode: file open mode
100 :param buffering: passed to builtins.open
101 :param encoding: passed to builtins.open
102 :param errors: passed to builtins.open
103 :param newline: passed to builtins.open
104 :return: output of file depending on options wrapped in a Sequence via seq
105 """
106 if not re.match("^[rbt]{1,3}$", mode):
107 raise ValueError("mode argument must be only have r, b, and t")
108
109 file_open = get_read_function(path, self.disable_compression)
110 file = file_open(
111 path,
112 mode=mode,
113 buffering=buffering,
114 encoding=encoding,
115 errors=errors,
116 newline=newline,
117 )
118 if delimiter is None:
119 return self(file)
120 else:
121 return self("".join(list(file)).split(delimiter))
122
123 def range(self, *args):
124 """

Callers 14

__iter__Method · 0.80
readMethod · 0.80
__iter__Method · 0.80
__iter__Method · 0.80
readMethod · 0.80
__iter__Method · 0.80
readMethod · 0.80
universal_write_openFunction · 0.80
test_openMethod · 0.80
test_open_gzipMethod · 0.80
test_open_bz2Method · 0.80
test_open_xzMethod · 0.80

Calls 2

get_read_functionFunction · 0.90
joinMethod · 0.80

Tested by 6

test_openMethod · 0.64
test_open_gzipMethod · 0.64
test_open_bz2Method · 0.64
test_open_xzMethod · 0.64