如何逐行阅读并对每一行进行一些操作

我这里有一个代码,可以读取csv文件中的行。每行。但是,我只需要读取一行,执行一项操作-也许调用另一个file.py,写入结果,然后采用第二行并以相同的方式继续即可。

现在它起作用了,这样循环就可以对我立即完成所有工作。有想法吗谢谢。

 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")
l1314121 回答:如何逐行阅读并对每一行进行一些操作

您最好的选择是将其加载到pandas DataFrame中,编写一行功能,然后使用apply() https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html

本文链接:https://www.f2er.com/3159789.html

大家都在问