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 should I read a file line-by-line in Python? - Stack Overflow

    Jul 19, 2012 · If iteration closed the file, I wouldn't be able to do that. So keeping iteration and resource management separate makes it easier to compose chunks of code into a larger, …

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

    Do you really want to read the entire text into one string variable? Do you really mean with "strip newlines" to replace them with an empty string? This would mean, that the last word of a line …

  5. Unicode (UTF-8) reading and writing to files in Python

    I'm having some brain failure in understanding reading and writing text to a file (Python 2.4).

  6. python - How do I read a text file as a string? - Stack Overflow

    Nov 12, 2018 · 29 text_file.readlines() returns a list of strings containing the lines in the file. If you want only a string, not a list of the lines, use text_file.read() instead. You also have another …

  7. How do I print the content of a .txt file in Python?

    Aug 15, 2013 · Anyways, I'm working on a piece of code that will open a file, print out the contents on the screen, ask you if you want to edit/delete/etc the contents, do it, and then re-print out …

  8. python reading text file - Stack Overflow

    Feb 26, 2014 · I have a text file, of which i need each column, preferably into a dictionary or list, the format is : N ID REMAIN VERS 2 2343333 bana twelve 3 3549287 m...

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

  10. Reading specific columns from a text file in python

    Jun 20, 2001 · I have a text file which contains a table comprised of numbers e.g: 5 10 6 6 20 1 7 30 4 8 40 3 9 23 1 4 13 6 if for example I want the numbers contained only in the second …