About 102,000 results
Open links in new tab
  1. Why should I close files in Python? - Stack Overflow

    Aug 1, 2014 · Open a file for writing in your python interpreter, write a string to it, then open that file in a text editor. On my system, the file will be empty until I close the file handle.

  2. What is a good way to handle exceptions when trying to read a …

    I want to read a .csv file in python. I don't know if the file exists. My current solution is below. It feels sloppy to me because the two separate exception tests are awkwardly juxtaposed. Is th...

  3. How to make file creation an atomic operation? - Stack Overflow

    Feb 25, 2010 · I am using Python to write chunks of text to files in a single operation: open (file, 'w').write (text) If the script is interrupted so a file write does not complete I want to have no file …

  4. How to do unit testing of functions writing files using Python's ...

    I prefer to have output functions explicitly accept a file handle (or file-like object), rather than accept a file name and opening the file themselves. This way, I can pass a StringIO object to …

  5. Does asyncio supports asynchronous I/O for file operations?

    Jan 9, 2016 · Does asyncio supports asynchronous I/O for file operations? If yes, how I can use this in Python 3.5 with async/await syntax code?

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

  7. Python file operations - Stack Overflow

    Jun 24, 2012 · Python uses stdio's fopen function and passes the mode as argument. I am assuming you use windows, since @Lev says the code works fine on Linux. The following is …

  8. python - Is it better to open/close a file every time vs keeping it ...

    Jul 5, 2012 · 0 IO operations consume too much time. Open and close the file, also. It's much faster if you open both files (the input and the output), use a memory buffer with, let's say, …

  9. file handling in python - Stack Overflow

    While it is easy enough to iterate in Python over some units you are still going to be constrained by memory. I don't think you want to read a line at a time and write it back out that would take …

  10. linux - How expensive are python file operations? or "How can …

    A commenter in another topic expressed the opinion that a file move is an expensive operation. I expected that python uses the Linux mv command which is very fast because it only involves …