About 2,360,000 results
Open links in new tab
  1. 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 me …

  2. 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 names in the file …

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

  4. How should I read a file line-by-line in Python? - Stack Overflow

    Jul 19, 2012 · In this case, it feels especially bad because iterators relate in a quasi-functional, value-based way to the contents of a file, but managing file handles is a completely separate task. …

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

    Jul 11, 2011 · 405 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 …

  6. python - How can I read a text file into a string variable and strip ...

    315 In Python 3.5 or later, using pathlib you can copy text file contents into a variable and close the file in one line:

  7. How to open and edit an existing file in Python? - Stack Overflow

    Dec 16, 2014 · The open() built-in Python method (doc) uses normally two arguments: the file path and the mode. You have three principal modes (the most used): r, w and a.

  8. python - Correct way to write line to file? - Stack Overflow

    May 28, 2011 · When the file is opened in text mode (the default), it is translated automatically to the correct line ending for the current platform. Writing "\r\n" would produce "\r\r\n" which is wrong.

  9. Easiest way to read/write a file's content in Python

    In Ruby you can read from a file using s = File.read (filename). The shortest and clearest I know in Python is with open (filename) as f: s = f.read () Is there any other way to do it that makes it

  10. python - What encoding does open () use by default? - Stack Overflow

    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 is the …