游标使用mySQL在python中执行实时数据

时间:2018-08-20 16:05:20

标签: python mysql

我有一个关于游标如何在python中执行查询的问题。这是有问题的代码块:

    state       county prime_mover       long      lat
 1:    AZ     Maricopa          GT -111.88668 33.58126
 2:    AZ     Maricopa          GT -111.88668 33.58126
 3:    CA  Los Angeles          CT -118.29410 34.06683
 4:    CA       Orange          CT -117.73632 33.69611
 5:    CA  Los Angeles          CT -118.29410 34.06683
 6:    CT    Fairfield          CT  -73.35118 41.29633
 7:    FL Hillsborough          GT  -82.47527 27.87826
 8:    IN       Morgan          CT  -86.49791 39.52721
 9:    MA   Barnstable          GT  -70.21598 41.79520
10:    MA    Nantucket          GT  -70.05841 41.29880
11:    MA        Essex          GT  -70.98384 42.64042
12:    MN       Dakota          GT  -93.04962 44.70344
13:    NJ     Cape May          CT  -74.80790 39.15476
14:    NJ        Salem          GT  -75.36532 39.58720
15:    NJ    Middlesex          CT  -74.42345 40.45429
16:    NY        Kings          GT  -73.95052 40.64792
17:    NC     Buncombe          CT  -82.50883 35.62002
18:    SC     Anderson          CT  -82.61956 34.57094
19:    TN       Shelby          CT  -89.99297 35.22379
20:    TX      Tarrant          CT  -97.29396 32.79856

因此,我要附加的所有列表都包含实时数据,这些数据会在第二秒发生变化。我已经注意到,当我在代码末尾打印read_time时,每次的列表都是完全相同的。我的问题是,执行查询后,数据是否始终相同?我希望看到这样的阅读时间:

for sleeper in range (2):
    cur.execute("QUERY")
    for row in cur:
        Demand.append(str(row[2]))
        ComponentID.append(str(row[3]))
        DeviceID.append(str(row[1]))
        read_time.append(str(row[4]))
print read_time
del read_time[:]

相反,我看到的是:

2018-08-20 15:39:08 
2018-08-20 15:59:25

0 个答案:

没有答案