About 622,000 results
Open links in new tab
  1. python - How to open a file using the open with statement - Stack …

    I'm looking at how to do file input and output in Python. I've written the following code to read a list of names (one per line) from a file into another file while checking a name against the name...

  2. open() in Python does not create a file if it doesn't exist

    Jun 3, 2010 · What is the best way to open a file as read/write if it exists, or if it does not, then create it and open it as read/write? From what I read, file = open ('myfile.dat', 'rw') should do this, right?...

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

    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 files for …

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

    Jul 11, 2011 · 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 readi...

  5. python - How to reliably open a file in the same directory as the ...

    Closed 2 years ago. I used to open files that were in the same directory as the currently running Python script by simply using a command like:

  6. function - How to Open a file through python - Stack Overflow

    Oct 22, 2013 · I am very new to programming and the python language. I know how to open a file in python, but the question is how can I open the file as a parameter of a function? example: function …

  7. python - How to replace/overwrite file contents instead of appending ...

    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 without needing …

  8. python - Why am I getting a FileNotFoundError? - Stack Overflow

    $ python script.py In order to make this work, the directory containing the python executable must be in the PATH, a so-called environment variable that contains directories that are automatically used for …

  9. 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 other writes). A few …

  10. How can I open multiple files using "with open" in Python?

    Since Python 3.3, you can use the class ExitStack from the contextlib module to safely open an arbitrary number of files. It can manage a dynamic number of context-aware objects, which means that it will …