Tags down


Searching python text file without for loops and if statments

By : ihammerstrom
Date : July 31 2020, 08:00 PM
around this issue Reading a sequential file (i.e. a text file) is always going to be a sequential process. Unless you can store it in separate chunks or skip ahead somehow it will be hard to do any parallel processing.
What you could do is separate the inherently sequential reading process from the searching process. This requires that the file content be naturally separated into chunks (i.e. lines) across which the search is not intended to find a result.
code :

Share : facebook icon twitter icon

Python Beginners - Searching a text file for an array of text

By : user3673243
Date : March 29 2020, 07:55 AM
hop of those help? I'm brand new to python. I have a text file full of strings. I want to see which of these multiple strings contain a set of keywords. I've managed to write this: , Are you searching for lines with all keywords included?
code :
keywords = ['abc', 'def', 'ghi']

for line in f:
    if all(keyword in line for keyword in keywords):
        print line

Searching a text file for a line of text matching the text inputted from a user Python

By : Roel van Lieshoud
Date : March 29 2020, 07:55 AM
may help you . When the user enters a phrase, key words out of the phrase needs to be matched to text in a text file and then the line out of the text file can be printed back to the user. , First these 2 lines do not work as per your requirement:
code :
question = raw_input(" Welcome to the phone help center, What is the problem?")
if question in ["screen", "display", "blank"]:
question = raw_input(" Welcome to the phone help center, What is the problem?")
for k in  ["screen", "display", "blank"]:
    if k in question:
        for line in searchfile:
            if k in line:             # or maybe  if 'screen' in line ?
                print line

Writing to file and using if statments with loops

By : user412459
Date : March 29 2020, 07:55 AM
seems to work fine So, there are a couple of things wrong about your program. I'll try to cover them all here before I show you the changes.
code :
do {
    // collect data
    do {
        // save or edit
    } while (!validChoice);

} while (!done);
#include <stdio.h>
#include <string.h>

int get_line(const char *prompt, char *dest, size_t size) {
  printf("%s", prompt);
  if (fgets(dest, size, stdin) == NULL) {
    dest[0] = '\0';
    return 0;
  dest[strcspn(dest, "\n")] = '\0';  // Lop off potential trailing '\n'
  return 1;

int main(void) 
    char first_name[20], surname[20], street_no[10], street_name[40], postcode[10], contact_no[20], save_edit_qu[10];
    int dd, mm, yy, done = 0;

    // Data collection loop: Runs as long as the user opts to edit the data.
    do {

        // Fetch data.
        get_line(" Enter first name:\n", first_name, sizeof first_name);
        get_line(" Enter surname:\n", surname, sizeof surname);
        get_line(" Contact Number\n", contact_no, sizeof contact_no);
        get_line(" Street Number\n", street_no, sizeof street_no);
        get_line(" Street Name\n", street_name, sizeof street_name);
        get_line(" Postcode\n", postcode, sizeof postcode);

        printf(" First Name : %s\n", first_name);
        printf(" Surname    : %s\n", surname);
        printf(" Contact No.: %s\n", contact_no);
        printf(" Street No. : %s\n", street_no);
        printf(" Stret Name : %s\n", street_name);
        printf(" Postcode   : %s\n", postcode);

        // Action loop: Runs as long as no valid input is given.
        do {
            get_line(" If the informations above is correct please enter SAVE/if you wish to change any informations please enter edit\n", save_edit_qu, sizeof save_edit_qu);

            // Option to quit.
            if (strcmp(save_edit_qu, "SAVE") == 0 || strcmp(save_edit_qu, "save") == 0) {
                fprintf(stdout, "Writing data to file...\n");
                // write data here.

                // Set done flag, and exit action loop.
                done = 1;

            // Option to edit.
            if (strcmp(save_edit_qu, "EDIT") == 0 || strcmp(save_edit_qu, "edit") == 0 ) {

                //loop back to beginning of report

            // Otherwise ask prompt again ^.
        } while (1);

    } while (!done);

    return 0;

How to break out of nested loops in Python when searching for a specific value in an Excel file?

By : user3573847
Date : March 29 2020, 07:55 AM
To fix this issue You have to put the logic inside while loop where you are taking the input and break from while loop when you find the shop address in file or based on your requirements.
code :
save = open('shop.txt', 'w')    
while not found:
    shop = int(input('Enter shop number: '))
    for row in ws.iter_rows(1):
        for cell in row:
            if cell.value == shop:
               print(ws.cell(row=cell.row, column=2).value, file = save)
               found = True
               # or you can write
               # break
        if found:
    if not found:
        print('Invalid shop number!')

searching for strings in a text file using foreach loops

By : Tomi Rahmansyah
Date : March 29 2020, 07:55 AM
it helps some times Remove the assignement of N/A inside the loop and let it run until completition.
At the end you could just test the content of the textboxes to see if your loops have found something and, if not, set the N/A text
Related Posts Related Posts :
  • Adding quotations around words preceding a colon in Python
  • Write a class that draws an image in the center of the screen in PyGame
  • Python requirements conflict with PyPi
  • A good way to make classes for more complex playing card types than those found in a standard deck?
  • How to find the longest chain of consecutively recurring character groupings in file
  • Class variable that is an instance of itself
  • SQLAlchemy(Python)/Sequelize(Node.js) rollback transation (undo button)
  • Word2Vec compare vectors from different models with different sizes
  • Pandas: Create a table with a “dummy variable” of another table
  • How to implement Python's multiprocessing Pool to convert thousands of files
  • Remove elements from lists, code is leaving just one
  • Ensure python script isn't run as root
  • How do I sum 2 specific column rows in a DataFrame if some of the values are NaN?
  • Mocking __init__ of a class imported in file
  • How to check a greater than check in reg expression?
  • How to make the progressbar work, It freezes the window
  • How to update the state of a Toggle Button after process completion?
  • How to specify the outer product of certain axis in python?
  • multiprocessing creates zombie process even after .join()
  • Why does the robot framework add quotation marks to a command string?
  • How to extract the orderconfirmedoid from from the current url using Selenium and Python
  • How to find a sum of even numbers in range recursively?
  • How to convert list of pixel into image using python
  • How can I bind the enter key to a command while having a button do the same thing?
  • python: subsetting and renaming columns by name in list of dataframes
  • print x over y in matplotlib python
  • Python Image Processing on Captcha how to remove noise
  • Pass value to string imported from another module using f-string
  • Greatest of 3 numbers code not working for specific numbers
  • Use of function inside a for loop
  • Cant match a particular pattern in regex using OR
  • when i build the docker with pip install psycopg2 has error
  • 'import ase' does not load submodule 'ase.io'
  • I have two tuple comparison. Almost the same data. Why this error:
  • Why hasn't this list changed?
  • Scrape html data using beautifulsoup and Python
  • JupyterLab - python open() function results in FileNotFoundError
  • I'm not getting proper output for checking a string to be palindrome or not
  • alphabet split instead of word split using lists
  • Celsius to Fahrenheit method doesn't work
  • How to import a module at each execution of python?
  • find contours of thresholded image
  • How to use sleep to limit data put in logs?
  • Dataframe expanding window and applying multiple functions
  • How to get integer list from a string but not integer list?
  • Rename dataframe in Python for loop
  • Unable to fetch rows from PostGresSQL table
  • How to pass values to a function which is a list item in Python
  • Easiest way to subclass a widget in Python for use with Qt Designer
  • Finding the cumulative sum of a list
  • Pandas Dataframe Update Rows
  • How to solve this loop problem in python flask?
  • Python Opencv: Filter Image for Text Detection
  • Python - Count Numbers of Different Digits in String
  • How to update, rotate and display a ply file with python?
  • Grouping by and filtering for column value containing string and aggregate function?
  • pandas group by day or week or month for timestamp
  • Django converting year to a full date
  • Clunky/slow dragging functionality on my analog clock project
  • Setting the labels of colorbar matplotlib
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org