About 711,000 results
Open links in new tab
  1. Difference between modes a, a+, w, w+, and r+ in built-in open …

    Oct 3, 2025 · 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 …

  2. python - File read using "open ()" vs "with open ... - Stack Overflow

    Jul 10, 2015 · 1 Comment "When you use with statement with open function, you do not need to close the file at the end, because with would automatically close it for you." I never knew about …

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

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

  5. 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?

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

  7. python - What encoding does open () use by default? - Stack …

    The default UTF-8 encoding of Python 3 only extends to conversions between bytes and str types. open() instead chooses an appropriate default encoding based on the environment: encoding …

  8. python - Purpose of including 'r' in the open () function ... - Stack ...

    Sep 3, 2015 · is not quite correct. The 'r' indicates that you wish to open the file in read mode; it does not read anything in itself. You can also read a file that is opened in other modes, …

  9. python - What does the argument newline='' do in the open …

    May 18, 2020 · 23 I was learning Python in Codecademy and they were talking about using the open() function for CSV files. I couldn't really understand what the argument newline='' meant …

  10. How do I mock an open used in a with statement (using the Mock ...

    Aug 29, 2020 · By patching the open function inside the __builtin__ module to my mock_open(), I can mock writing to a file without creating one. Note: If you are using a module that uses …