About 1,720,000 results
Open links in new tab
  1. How should I read a file line-by-line in Python? - Stack Overflow

    Jul 19, 2012 · @thebjorn: perhaps, but the Python 2.1 example you cited were not safe from unclosed file handler in alternate implementations. A Python 2.1 file reading that is safe from …

  2. python - How to read a file line-by-line into a list? - Stack Overflow

    How do I read every line of a file in Python and store each line as an element in a list? I want to read the file line by line and append each line to the end of the list.

  3. Difference in read (), readline () and readlines () in Python

    Sep 24, 2019 · In the commands read(), readline() and readlines(), one difference is of course reading whole file, or a single line, or specified line. But I didn't understand the use/necessity …

  4. python - When should I ever use file.read () or file.readlines ...

    Jun 29, 2016 · Please clarify. is the timeit measurement for read, or for readlines? I'd expect the read loop to take longer because it returns a single string, so iterating over it would go …

  5. python - How do I read from stdin? - Stack Overflow

    In Python 2, this is raw_input(prompt). open(0).read() - In Python 3, the builtin function open accepts file descriptors (integers representing operating system IO resources), and 0 is the …

  6. Python: How to properly use readline () and readlines ()

    Dec 25, 2018 · 2 If you are using readline() function, you have to remember that this function only returns a line, so you have to use a loop to go through all of the lines in the text files. In case of …

  7. python - Read file from line 2 or skip header row - Stack Overflow

    Jan 25, 2011 · How can I skip the header row and start reading a file from line2?

  8. python - How to read specific lines from a file (by line number ...

    I'm using a for loop to read a file, but I only want to read specific lines, say line #26 and #30. Is there any built-in feature to achieve this?

  9. python - How to read a file without newlines? - Stack Overflow

    In Python, calling e.g. temp = open (filename,'r').readlines () results in a list in which each element is a line from the file. However, these strings have a newline character at the end, which I do...

  10. How to while loop until the end of a file in Python without …

    Mar 13, 2015 · The call to readline() on a line with no text will return "\n", while at the end of the file it will return "" (an empty string). Another alternative is to call read() to get all of the file's …