10 examples of 'python readlines without newline' in Python

Every line of 'python readlines without newline' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
280def readlines(self):
281 """Read and return the list of all logical lines remaining in the
282 current file."""
283
284 lines = []
285 while True:
286 line = self.readline()
287 if line is None:
288 return lines
289 lines.append(line)
1033def readlines(filename):
1034 f = open(filename)
1035 try:
1036 return f.readlines()
1037 finally:
1038 f.close()
42def readLines(in_file):
43 """Returns a list of lines from a input markdown file."""
44
45 with open(in_file, 'r') as inf:
46 in_contents = inf.read().split('\n')
47 return in_contents
11def readlines(self):
12 return self.lines
195def readlines(self, numberOfBytesHint = None):
196 # The documentation for readlines is not consistent with the other
197 # read methods as to what constitutes a valid default parameter.
198 # Testing shows that neither None nor -1 are acceptable so we
199 # use None and specifically check for it.
200 if numberOfBytesHint is None:
201 return self.file.readlines()
202 else:
203 return self.file.readlines(numberOfBytesHint)
230def readline(self, limit=-1):
231 """
232 Public method to read one line from file.
233
234 @keyparam limit maximum bytes to read or all if limit=-1 (int)
235 @return decoded line read
236 """
237 txt = super(File, self).readline(limit)
238 if self.__encoding is None:
239 return txt
240 else:
241 return codecs.decode(txt, self.__encoding)
63def call_readlines(self, i):
64 self.assertEqual(i.readlines(), ["Line 1\n", "Line 2\n", "Line 3\n", "Line 4\n", "Line 5"])
65 self.assertEqual(i.readlines(), [])
66 i.close()
67 self.assertRaises(ValueError, i.readlines)
1175def readlines(self, size = None):
1176 res = []
1177 while True:
1178 line = self.readline()
1179 if line is not None:
1180 res.append(line)
1181 else:
1182 break
1183
1184 return res
60def _read_file_lines(file_):
61 """Read lines of file
62 file_: either path to file or a file (like) object.
63 Return list of lines read or 'None' if file does not exist.
64 """
65 cont_str = _read_file(file_)
66 if cont_str is None:
67 return None
68 return [url_str.rstrip() for url_str in cont_str.splitlines()]
88def test_readline(self, space, tmpdir):
89 contents = "01\n02\n03\n04\n"
90 f = tmpdir.join("file.txt")
91 f.write(contents)
92 w_res = space.execute("return File.new('%s').readline" % f)
93 assert self.unwrap(space, w_res) == "01\n"
94
95 w_res = space.execute("return File.new('%s').readline('3')" % f)
96 assert self.unwrap(space, w_res) == "01\n02\n03"
97
98 w_res = space.execute("return File.new('%s').readline(1)" % f)
99 assert self.unwrap(space, w_res) == "0"
100
101 w_res = space.execute("return File.new('%s').readline('3', 4)" % f)
102 assert self.unwrap(space, w_res) == "01\n0"

Related snippets