mardi 22 septembre 2020

Why does this if statement not execute inside of the for loop?

mgq_list = [] 
**# creating a list to place in values from a text file**
for lines_mgq in mgq_values: **# mgq_values is a text file by readlines**
    mgq_list.append(lines_mgq) 

int_col = 1 

for line in contents_text_file: #contents_text_file is populated with lines of notes
                    time.sleep(3)
                    str_col = str(int_col) # taking the int_col turning into a string
                    column_range = 'A' + str_col #creating a column range with the str_col counter
                    tab.update(column_range, line) #updating specific google sheet by column range
                    value_for_match = tab.acell(column_range).value #value_of_match gets current value
                
                    for line_mgq in mgq_list: # for value in list
                        if line_mgq in value_for_match: # if value of list is the in current column** 
                             tab.format(column_range, { # update background color to green if valid
                                "backgroundColor":{
                                    "green":1.0, 
                                }
                            })
                    int_col += 1 # increment column range

So what I am trying to do is take a value (str) from google sheets, and run it through a list of items (str). If the value is valid by one of the list items the background of the current column should change to green.

I was able to print out the actual values and that the list actually contained some values from the google sheet tab. Not sure where to go from here.

I was recommended to try it in a json format but I don't want to back track.

Aucun commentaire:

Enregistrer un commentaire