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

  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. 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:

  4. 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.

  5. python - How to open a file for both reading and writing ... - Stack ...

    Jul 11, 2011 · 405 Is there a way to open a file for both reading and writing? As a workaround, I open the file for writing, close it, then open it again for reading. But is there a way to open a file for both …

  6. Read text file and parse in python - Stack Overflow

    Jul 15, 2018 · With this data I want to do the followings: 1) Read the text file by line as a separate element in the list Split elements by comma Delete non-necessary elements ('\n') in the list For the …

  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. How to read a text file into a list or an array with Python

    Feb 4, 2013 · I am trying to read the lines of a text file into a list or array in python. I just need to be able to individually access any item in the list or array after it is created. The text file is form...

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

  10. How to read a json file and return as dictionary in Python

    Jan 5, 2017 · How to read a json file and return as dictionary in Python Asked 9 years, 1 month ago Modified 5 years, 2 months ago Viewed 40k times