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

    401 Python allows putting multiple open() statements in a single with. You comma-separate them. Your code would then be: def filter(txt, oldfile, newfile): '''\ Read a list of names from a file line …

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

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

    In the rare case that you want to open a variable number of files all at the same time, you can use contextlib.ExitStack, starting from Python version 3.3: with ExitStack() as stack: files = …

  5. python - Reading JSON from a file - Stack Overflow

    If you are reading the data from the Internet instead, the same techniques can generally be used with the response you get from your HTTP API (it will be a file-like object); however, it is …

  6. python - open read and close a file in 1 line of code - Stack Overflow

    The shortest, built-in way to achieve opening, reading, and closing a file in Python is using 2 logical lines whether it's condensed down to 1 line or not. So I don't see this answer to be …

  7. file - Python open () requires full path - Stack Overflow

    Jun 8, 2017 · Python provides us with an attribute called __file__ that returns the absolute path to the file. For example, say that the content of first_file.py is just one line that prints this path: …

  8. Python can't find file - Stack Overflow

    The file itself is located in the same folder as the script file trying to open it: C:\Users\User\Desktop\Python stuff\Data.txt for simplicity, the simplest means to access the …

  9. How do I open a text file in Python? - Stack Overflow

    Oct 18, 2016 · Currently I am trying to open a text file called "temperature.txt" i have saved on my desktop using file handler, however for some reason i cannot get it to work. Could anyone tell …

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