About 50 results
Open links in new tab
  1. 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.

  2. Easiest way to read/write a file's content in Python

    In Ruby you can read from a file using s = File.read (filename). The shortest and clearest I know in Python is with open (filename) as f: s = f.read () Is there any other way to do it that makes it

  3. How do you read a file into a list in Python? - Stack Overflow

    Oct 13, 2010 · 133 Two ways to read file into list in python (note these are not either or) - use of with - supported from python 2.5 and above use of list comprehensions 1. use of with This is the pythonic …

  4. python - How can I read a text file into a string variable and strip ...

    315 In Python 3.5 or later, using pathlib you can copy text file contents into a variable and close the file in one line:

  5. How should I read a file line-by-line in Python? - Stack Overflow

    Jul 19, 2012 · In this case, it feels especially bad because iterators relate in a quasi-functional, value-based way to the contents of a file, but managing file handles is a completely separate task. …

  6. 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?

  7. How can I parse a YAML file in Python - Stack Overflow

    Nov 23, 2015 · The script can parse yaml from a file (function load), parse yaml from a string (function loads) and convert a dictionary into yaml (function dumps). It respects all variable types.

  8. python - Reading binary file and looping over each byte - Stack Overflow

    In Python, how do I read in a binary file and loop over each byte of that file?

  9. python - How to read a large file - line by line? - Stack Overflow

    Nov. 2022 Edit: A related question that was asked 8 months after this question has many useful answers and comments. To get a deeper understanding of python logic, do also read this related question …

  10. python - How can I read large text files line by line, without loading ...

    Jun 25, 2011 · I want to read a large file (>5GB), line by line, without loading its entire contents into memory. I cannot use readlines() since it creates a very large list in memory.