【问题标题】:Read data from csv file and pass the values into sql statment using python从 csv 文件中读取数据并使用 python 将值传递给 sql 语句
【发布时间】:2018-08-09 09:57:43
【问题描述】:
seqno   soursequery targetquery
1   select count(*) from table  select count(*) from table
2   select count(*) from table  select count(*) from table

我有上面的 csv 文件,我必须阅读 seqno 和两个查询并比较 Python 中的结果。我必须将测试用例状态放在同一个文件中。

预期: 如果seqno 为 1,我必须读取前两个查询(源和目标)并比较两个查询的计数。

谢谢, 提前

【问题讨论】:

    标签: python sql csv


    【解决方案1】:

    我想你想要这样的东西。

    # Select All From CSV File Where
    
    import csv
    # Asks for search criteria from user
    search_parts = input("Enter search criteria:\n").split(",")
    # Opens csv data file
    file = csv.reader(open("C:\\your_path_here\\test.csv"))
    # Go over each row and print it if it contains user input.
    for row in file:
        if all([x in row for x in search_parts]):
            print(row)
    

    【讨论】:

    • 其实我想从文件中读取第一行,我必须比较两个表的计数...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 2020-05-09
    • 2019-11-03
    • 2013-10-12
    • 1970-01-01
    相关资源
    最近更新 更多