About 50 results
Open links in new tab
  1. 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 …

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

  3. How to read and write INI file with Python3? - Stack Overflow

    I need to read, write and create an INI file with Python3. FILE.INI default_path = "/path/name/" default_file = "file.txt" Python File: # Read file and and create if it not exists config = in...

  4. python - How do I write JSON data to a file? - Stack Overflow

    How do I write JSON data stored in the dictionary data to a file? f = open ('data.json', 'wb') f.write (data) This gives the error: TypeError: must be string or buffer, not dict

  5. How to write to an Excel spreadsheet using Python?

    A csv file is a text file that is formatted in a certain way: each line is a list of values, separated by commas. Python programs can easily read and write text, so a csv file is the easiest and …

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

    Oct 3, 2025 · Python on Windows makes a distinction between text and binary files; the end-of-line characters in text files are automatically altered slightly when data is read or written.

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

    Jun 3, 2010 · The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing. - Python file modes …

  8. How to read HDF5 files in Python - Stack Overflow

    Jan 27, 2015 · I am trying to read data from hdf5 file in Python. I can read the hdf5 file using h5py, but I cannot figure out how to access data within the file. My code import h5py import numpy …

  9. python - How to read a file line-by-line into a list? - Stack Overflow

    How do I read every line of a file in Python and store each line as an element in a list? I want to read the file line by line and append each line to the end of the list.

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