About 805,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 - How can I read a text file into a string variable and strip ...

    Oct 18, 2016 · In Python 3.5 or later, using pathlib you can copy text file contents into a variable and close the file in one line: from pathlib import Path txt = Path('data.txt').read_text() and then …

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

    Jun 6, 2017 · In the interest of not rewriting an open source library, I want to treat a string of text as a file in python 3. Suppose I have the file contents as a string: not_a_file = 'there is a lot of …

  4. python - How to search for a string in text files? - Stack Overflow

    Takes an absolute file path and a given string and passes it to word_find(), uses readlines() method on the given file within the enumerate() method which gives an iterable count as it …

  5. python - How to search and replace text in a file - Stack Overflow

    python string find and replace in text file. 0. replace a string within file using python. 4. Replacing ...

  6. python - Replace string within file contents - Stack Overflow

    If you wanted a change more complex than a single replacement, you would assign the result of read_text to a variable, process it and save the new content to another variable, and then save …

  7. python - How do I read a text file as a string? - Stack Overflow

    Nov 12, 2018 · text_file.readlines() returns a list of strings containing the lines in the file. If you want only a string, not a list of the lines, use text_file.read() instead. You also have another …

  8. python - Search File And Find Exact Match And Print Line ... - Stack ...

    Jan 12, 2017 · Here's the the problem I have, I'm trying to have a python script search a text file, the text file has numbers in a list and every number corresponds to a line of text and if the …

  9. Check if a string is in a file with Python - Stack Overflow

    I'm new to Python and I'm trying to figure out how I can search for a string in a file and use it as a condition in a if clause: If "String" is in the file, Print("Blablabla")

  10. python - How to delete specific strings from a file ... - Stack Overflow

    C:\Just_Testing>python remove_text.py works exactly the same. Of course, like when writing HTML, I guess it never hurts to use a fully qualified path when running py or python from …

Refresh