About 354,000 results
Open links in new tab
  1. python - How to search for a string in text files? - Stack Overflow

    Here's another. 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 traverses line by line, in the end giving you the line with the matching string, plus the given line number. Cheers.

  2. 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 raw_input match's the exact number in the text file it prints that whole line of text. so far It prints any line containing the the number.

  3. python - The fastest way to find a string inside a file - Stack Overflow

    May 6, 2016 · I have tried many ways of looking for a string inside a file, but all were slow. All I need is: look for a string inside a file; print the line on which the string is; All I've been doing until now was reading a file (tried many ways) and then checking whether the string I am looking for is located in the current line. If not, check the next ...

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

  5. Find a file in python - Stack Overflow

    Nov 12, 2009 · I have a file that may be in a different place on each user's machine. Is there a way to implement a search for the file? A way that I can pass the file's name and the directory tree to search in?

  6. python - Get Line Number of certain phrase in text file - Stack …

    Iterating through a file using for line in f is much better than for line in f.readlines(). The former is pythonic (e.g., would work if f is any generic iterable; not necessarily a file object that implements readlines), and more efficient f.readlines() creates an list with the

  7. 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")

  8. Searching/reading binary data in Python - Stack Overflow

    Oct 16, 2018 · The code to do this depends on a couple things. If you open the file in binary mode and you're using Python 3 (both of which are probably best practice for this scenario), you'll need to search for a byte string (as opposed to a character string), which …

  9. Find files in a directory containing desired string in Python

    Dec 30, 2015 · I'm trying to find a string in files contained within a directory. ... Find all files in folder containing ...

  10. python - Check whether string is in CSV - Stack Overflow

    Note that username must be defined previously. Also change the name of the file. The code loops through all the lines in the CSV file. row a list of string containing each element of your row. For example, if you have this in your CSV file: Joe,Peter,Michel the row will be ['Joe', 'Peter', 'Michel']. Then you can check if your username is in ...

Refresh