About 377,000 results
Open links in new tab
  1. python - Correct way to write line to file? - Stack Overflow

    May 28, 2011 · the_file.write('Hello\n') From The Documentation: Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all …

  2. Writing string to a file on a new line every time - Stack Overflow

    May 27, 2010 · I want to append a newline to my string every time I call file.write(). What's the easiest way to do this in Python?

  3. python - How do I append to a file? - Stack Overflow

    Jan 16, 2011 · with open('/path/to/file', 'a+') as file: file.write("Additions to file") file.close() The a+ in the open(...) statement instructs to open the file in append mode and allows read and write …

  4. python - How to append new data onto a new line - Stack Overflow

    This uses a backslash escape, \n, which Python converts to a newline character in string literals. It just concatenates your string, name, and that newline character into a bigger string, which gets …

  5. Telling Python to save a .txt file to a certain directory on Windows ...

    Nov 6, 2011 · How do you tell Python where to save a text file? For example, my computer is running the Python file off my desktop. I want it to save all the text file in my documents folder, …

  6. python - How to replace/overwrite file contents instead of …

    When you say "replace the old content that's in the file with the new content", you need to read in and transform the current contents data = file.read(). You don't mean "blindly overwrite it …

  7. write multiple lines in a file in python - Stack Overflow

    an improvement would be to construct the readme_text before you open the file. Also note that when opening a file in text mode ("r", "w"), Python already handles the platform dependent …

  8. python - Difference between modes a, a+, w, w+, and r+ in built …

    In Python's built-in open function, what is the difference between the modes w, a, w+, a+, and r+? The documentation implies that these all allow writing to the file, and says that they open the …

  9. python - How do I write JSON data to a file? - Stack Overflow

    How do I write JSON data stored in the dictionary data to a file? f = open ('data.json', 'wb') f.write (data) This gives the error: TypeError: must be string or buffer, not dict

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

    If you want to read and write encoded files in Python, best use the codecs module. Pasting text between the terminal and applications is difficult, because you don't know which program will …