在python中将数据更新到数据库中

时间:2017-11-11 21:10:30

标签: python python-2.7 sqlite

我在将数据更新到数据库时遇到了问题。当我运行代码时,它会将以youtube-dl开头的数据输入到3061,它应该是30703001,然后是3010 3020 { {1}} {3021 {1}} {3030 {1}} {3061 {1}} 3070`。

当我尝试这个时:

3011 to

它将使数据库表显示如下:

,

应该是:

to

以下是until to数据:

to

以下是for next_day, program_id in zip(nextday_list, program_id_list): value = program_id for i in range(0,10): if value == program_id: cur.execute("UPDATE programs SET program_id=? WHERE start_date=?",(value, next_day)) 列表:

channel             |   start_date     |  program_id
101 BBC One South E |  20171111230000  |  3061
101 BBC One South E |  20171111233000  |  3062
101 BBC One South E |  20171112000000  |  3063
101 BBC One South E |  20171112013500  |  3064
101 BBC One South E |  20171112014000  |  3065
101 BBC One South E |  20171112060000  |  3066
101 BBC One South E |  20171112090000  |  3067
101 BBC One South E |  20171112102000  |  3068
101 BBC One South E |  20171112123000  |  3069
101 BBC One South E |  20171112133000  |  3070
102 BBC Two         | 20171111232500   |  3061
102 BBC Two         | 20171112010000   |  
102 BBC Two         | 20171112023500   |  
102 BBC Two         | 20171112060500   |  
102 BBC Two         | 20171112065000   |  
102 BBC Two         | 20171112073500   |  
102 BBC Two         | 20171112083500   |  
102 BBC Two         | 20171112093000   |  
102 BBC Two         | 20171112130000   |  
102 BBC Two         | 20171112140000   |  

以下是channel | start_date | program_id 101 BBC One South E | 20171111230000 | 3001 101 BBC One South E | 20171111233000 | 3002 101 BBC One South E | 20171112000000 | 3003 101 BBC One South E | 20171112013500 | 3004 101 BBC One South E | 20171112014000 | 3005 101 BBC One South E | 20171112060000 | 3006 101 BBC One South E | 20171112090000 | 3007 101 BBC One South E | 20171112102000 | 3008 101 BBC One South E | 20171112123000 | 3009 101 BBC One South E | 20171112133000 | 3010 102 BBC Two | 20171111232500 | 3011 102 BBC Two | 20171112010000 | 3012 102 BBC Two | 20171112023500 | 3013 102 BBC Two | 20171112060500 | 3014 102 BBC Two | 20171112065000 | 3015 102 BBC Two | 20171112073500 | 3016 102 BBC Two | 20171112083500 | 3017 102 BBC Two | 20171112093000 | 3018 102 BBC Two | 20171112130000 | 3019 102 BBC Two | 20171112140000 | 3020 列表:

program_id

我也试过这个:

3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070

它没有任何区别。我期待做的是我想从我的列表中找到匹配的program_id_list字符串来检查数据库以查看字符串是否匹配然后我想在10行中输入程序ID找到匹配的['3001', '3002', '3003', '3004', '3005', '3006', '3007', '3008', '3009', '3010', '3011', '3012', '3013', '3014', '3015', '3016', '3017', '3018', '3019', '3020', '3021', '3022', '3023', '3024', '3025', '3026', '3027', '3028', '3029', '3030', '3031', '3032', '3033', '3034', '3035', '3036', '3037', '3038', '3039', '3040', '3041', '3042', '3043', '3044', '3045', '3046', '3047', '3048', '3049', '3050', '3051', '3052', '3053', '3054', '3055', '3056', '3057', '3058', '3059', '3060', '3061', '3062', '3063', '3064', '3065', '3066', '3067', '3068', '3069', '3070'] 字符串,然后为每个通道输入10行其他10个程序ID。

这是例如:我的列表中的nextday_list字符串显示['20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000', '20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000', '20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000', '20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000', '20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000', '20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000', '20171111224000', '20171111230000', '20171111233000', '20171112000000', '20171112013500', '20171112014000', '20171112060000', '20171112090000', '20171112102000', '20171112123000'] 因为我想在BBC One的数据库中检查它们,当找到匹配的字符串时我想输入10个程序ID从for next_day, program_id in zip(nextday_list, program_id_list): value = program_id if value == program_id: cur.execute("UPDATE programs SET program_id=? WHERE start_date=?",(value, next_day)) 开始到next_day,因为我想在相同的行中输入它们,在列表中找到匹配的字符串,在数据库中进行比较。然后在此之后我想跳到下一个通道找到与next_day字符串匹配的10行,所以我想输入程序ID next_day到3020`以在每行中输入它们。其他渠道也是如此。

你能告诉我一个例子,我如何输入10行与匹配的20171111224000字符串相同的行中的程序ID,这样我可以对其他频道做同样的事情吗?

0 个答案:

没有答案