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

    May 28, 2011 · 1387 How do I write a line to a file in modern Python? I heard that this is deprecated: print >>f, "hi there" Also, does "\n" work on all platforms, or should I use "\r\n" on …

  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 to write a list of numbers as bytes to a binary file ...

    With Python 2 on Windows, I found that writing a bytearray still converts \n to \r\n, making it unsatisfactory for binary data, if the "b" flag is not passed when opening the file.

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

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

    Jan 16, 2011 · On some operating systems, opening the file with 'a' guarantees that all your following writes will be appended atomically to the end of the file (even as the file grows by …

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

  7. python - Directing print output to a .txt file - Stack Overflow

    Is there a way to save all of the print output to a txt file in python? Lets say I have the these two lines in my code and I want to save the print output to a file named output.txt.

  8. How to write to a file, using the logging Python module?

    Jun 17, 2011 · How can I use the logging module in Python to write to a file? Every time I try to use it, it just prints out the message.

  9. How can I write data in YAML format in a file? - Stack Overflow

    Sep 18, 2012 · How can I write data in YAML format in a file? Asked 13 years, 1 month ago Modified 6 months ago Viewed 405k times

  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 …