About 341,000 results
Open links in new tab
  1. python - Print string to text file - Stack Overflow

    Jan 26, 2017 · In the following code, I want to substitute the value of a string variable TotalAmount into the text document, with Python: text_file = open("Output.txt", "w") …

  2. python - Writing string to a file on a new line every time - Stack …

    Oct 23, 2017 · file.write(your_string + '\n') as suggested by another answer, but why using string concatenation (slow, error-prone) when you can call file.write twice: file.write(your_string) …

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

    May 28, 2011 · You should use the print() function which is available since Python 2.6+. from __future__ import print_function # Only needed for Python 2 print("hi there", file=f)

  4. Writing Strings to files in python - Stack Overflow

    Mar 22, 2010 · What version of Python are you using? In Python 3.x a string contains Unicode text in no particular encoding. To write it out to a stream of bytes (a file) you must convert it to …

  5. Treat a string as a file in python - Stack Overflow

    Jun 6, 2017 · Suppose I have the file contents as a string: not_a_file = 'there is a lot of blah blah in this so-called file' I want to treat this variable, i.e. the contents of a file, as a path-like object …

  6. writing a list to a txt file in python - Stack Overflow

    Dec 2, 2013 · writelines() needs a list of strings with line separators appended to them but your code is only giving it a list of integers.

  7. python - How do I append to a file? - Stack Overflow

    Jan 16, 2011 · position 1000 (for example) writer2: seek to end of file. position 1000 writer2: write data at position 1000 end of file is now 1000 + length of data. writer1: write data at position …

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

    To get utf8-encoded file as opposed to ascii-encoded in the accepted answer for Python 2 use:. import io, json with io.open('data.txt', 'w', encoding='utf-8') as f: f.write(json.dumps(data, …

  9. python - Writing Unicode text to a text file? - Stack Overflow

    May 18, 2011 · The file opened by codecs.open is a file that takes unicode data, encodes it in iso-8859-1 and writes it to the file. However, what you try to write isn't unicode; you take unicode …

  10. file - Python writing binary - Stack Overflow

    When you open a file in binary mode, then you are essentially working with the bytes type. So when you write to the file, you need to pass a bytes object, and when you read from it, you get …

Refresh