8 examples of 'python readlines' in Python

Every line of 'python readlines' 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
this disclaimer
1033def readlines(filename):
1034 f = open(filename)
1035 try:
1036 return f.readlines()
1037 finally:
1038 f.close()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

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)
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)
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)
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
54def readlines(self, sizehint=None):
55 x = []
56 for line in self.raw_readlines():
57 x.append(line+'\n')
58 return x
621def readlines (self):
622 self.wait ()
623
624 if self.captured_lines is not None:
625 lines= self.captured_lines
626 else:
627 self.prepare_capture_file ()
628 if self.capture_file is not None: # TODO: test
629 lines= self.capture_file.readlines ()
630 logger.debug ('closing %r', self.capture_file)
631 self.capture_file.close ()
632 else:
633 lines = None
634
635 return lines
215def readlines(self, file):
216 """
217 Read file lines since last access until EOF is reached and
218 invoke callback.
219 """
220 while True:
221 lines = file.readlines(self._sizehint)
222 if not lines:
223 break
224 self._callback(file.name, lines)

Related snippets