0

I have a code here that reads the lines from the csv file. Each line. However, I need to read only one line, perform an operation - perhaps call another file.py, write the result, and then take the second line and continue the same way.

Now it works so that the cycle does everything to me at once. Some idea? Thank you.

 with open(csv_user_file) as csv_file:
        csv_file = csv.reader(csv_file, delimiter=',')
        line_count = 0
        for row in csv_file:
            if line_count == 0:
                self.driver.implicitly_wait(30)
                print(row[0], '|', row[1])
                u = row[0]
                p = row[1]
                print("Login")
                username = self.driver.find_element_by_id("username")
                password = self.driver.find_element_by_id("password")
                username.send_keys(u)
                password.send_keys(p)
                self.driver.implicitly_wait(30)
                ButtonLogin = self.driver.find_element_by_id("kc-login").click()
                self.driver.implicitly_wait(50)


            else:
                exit()
                print("Not FOUND")
Tomasito
  • 306
  • 2
  • 15

1 Answers1

0

Your best bet is to load it into a pandas DataFrame, write the function for one row, and then use apply() https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html

Tim Bradley
  • 173
  • 6
  • Would there be any advice on how to apply this to my particular case? I'm new to Python and I've been worried about it for a few days. – Tomasito Nov 07 '19 at 10:18
  • Basically read the CSV into pandas using pandas.read_csv(), then write a separate function that would operate on a row. I could write it all out, but this answer gives a very good simple example, you could still index with numbers, or the column name (if the csv has a header) https://stackoverflow.com/questions/13331698/how-to-apply-a-function-to-two-columns-of-pandas-dataframe – Tim Bradley Nov 07 '19 at 15:43