for keys, values in data_frame.iterrows():
new_dict = {
'歌曲名': values['歌曲名'],
'歌手名': values['歌手名'],
'中央曲库ID': values['中央曲库歌曲ID']
}
if '伴奏' in str(values['歌曲名']):
sql = 'select song_id from songs_ip where center_inst_ids like "%s" ' \
'and company_id=4 and deleted_at is null;' % values['中央曲库歌曲ID']
else:
sql = 'select song_id from songs_ip where center_ids like "%s" ' \
'and company_id=4 and deleted_at is null;' % values['中央曲库歌曲ID']
cursor.execute(sql)
if cursor.fetchone():
print(cursor.fetchone())
song_id = cursor.fetchone()
print(song_id)
else:
print(0)
写了一串这样的代码,如果不判断cursor.fetchone()是否为空值,那么cursor.fetchone()可以打印出来,一旦判断之后全部为空不知道为什么.